@@ -1399,6 +1399,7 @@ function initializeZval(string $zvalName, $value): string
1399
1399
if ($ value === "" ) {
1400
1400
$ code .= "\tZVAL_EMPTY_STRING(& $ zvalName); \n" ;
1401
1401
} else {
1402
+ $ value = addslashes ($ value );
1402
1403
$ code .= "\tzend_string * {$ zvalName }_str = zend_string_init( \"$ value \", sizeof( \"$ value \") - 1, 1); \n" ;
1403
1404
$ code .= "\tZVAL_STR(& $ zvalName, {$ zvalName }_str); \n" ;
1404
1405
}
@@ -1434,66 +1435,6 @@ abstract protected function getFieldsynopsisLinkend(): string;
1434
1435
1435
1436
abstract protected function getFieldsynopsisValueString (): ?string ;
1436
1437
1437
- /**
1438
- * @param mixed $value
1439
- */
1440
- protected function initializeValue (string $ type , $ value , bool $ isTyped ): string
1441
- {
1442
- $ name = $ this ->getVariableLikeName ();
1443
- $ zvalName = $ this ->getVariableTypeCode () . "_ {$ name }_value " ;
1444
-
1445
- $ code = "\tzval $ zvalName; \n" ;
1446
-
1447
- switch ($ type ) {
1448
- case "undefined " :
1449
- if ($ isTyped ) {
1450
- $ code .= "\tZVAL_UNDEF(& $ zvalName); \n" ;
1451
- } else {
1452
- $ code .= "\tZVAL_NULL(& $ zvalName); \n" ;
1453
- }
1454
- break ;
1455
-
1456
- case "NULL " :
1457
- $ code .= "\tZVAL_NULL(& $ zvalName); \n" ;
1458
- break ;
1459
-
1460
- case "boolean " :
1461
- $ code .= "\tZVAL_BOOL(& $ zvalName, " . ((int ) $ value ) . "); \n" ;
1462
- break ;
1463
-
1464
- case "integer " :
1465
- $ code .= "\tZVAL_LONG(& $ zvalName, $ value); \n" ;
1466
- break ;
1467
-
1468
- case "double " :
1469
- $ code .= "\tZVAL_DOUBLE(& $ zvalName, $ value); \n" ;
1470
- break ;
1471
-
1472
- case "string " :
1473
- if ($ value === "" ) {
1474
- $ code .= "\tZVAL_EMPTY_STRING(& $ zvalName); \n" ;
1475
- } else {
1476
- $ value = addslashes ($ value );
1477
- $ code .= "\tzend_string * {$ zvalName }_str = zend_string_init( \"$ value \", sizeof( \"$ value \") - 1, 1); \n" ;
1478
- $ code .= "\tZVAL_STR(& $ zvalName, {$ zvalName }_str); \n" ;
1479
- }
1480
- break ;
1481
-
1482
- case "array " :
1483
- if (empty ($ value )) {
1484
- $ code .= "\tZVAL_EMPTY_ARRAY(& $ zvalName); \n" ;
1485
- } else {
1486
- throw new Exception ("Unimplemented " . $ this ->getVariableTypeName () . " value " );
1487
- }
1488
- break ;
1489
-
1490
- default :
1491
- throw new Exception ("Invalid " . $ this ->getVariableTypeName () . " value " );
1492
- }
1493
-
1494
- return $ code ;
1495
- }
1496
-
1497
1438
protected function getFlagsAsString (): string
1498
1439
{
1499
1440
$ flags = "ZEND_ACC_PUBLIC " ;
@@ -1619,8 +1560,6 @@ protected function getFieldsynopsisValueString(): ?string
1619
1560
1620
1561
public function getDeclaration (): string
1621
1562
{
1622
- $ constName = $ this ->name ->const ;
1623
-
1624
1563
$ constantValue = false ;
1625
1564
$ value = $ this ->evaluateValue ($ this ->value , $ constantValue );
1626
1565
$ valueType = gettype ($ value );
@@ -1677,16 +1616,16 @@ private function getConstDeclaration(string $code, $value, string $valueType): s
1677
1616
return $ code ;
1678
1617
}
1679
1618
1680
- private function getClassConstDeclaration (string $ code , mixed $ value, string $ valueType ): string
1619
+ private function getClassConstDeclaration (string $ code , mixed $ value ): string
1681
1620
{
1682
- $ constName = $ this ->name ;
1621
+ $ constName = $ this ->getVariableLikeName () ;
1683
1622
1684
- $ code .= "\n" . $ this -> initializeValue ( $ valueType , $ value, false );
1623
+ $ code .= "\n" . initializeZval ( " const_ { $ constName } _value " , $ value );
1685
1624
1686
1625
$ code .= "\tzend_string *const_ {$ constName }_name = zend_string_init_interned( \"$ constName \", sizeof( \"$ constName \") - 1, 1); \n" ;
1687
1626
$ nameCode = "const_ {$ constName }_name " ;
1688
1627
1689
- $ code .= "\tzend_declare_class_constant_ex(class_entry, $ nameCode, &const_ {$ constName }_value, " . $ this ->getFlagsAsString ($ this -> isDeprecated ) . ", NULL); \n" ;
1628
+ $ code .= "\tzend_declare_class_constant_ex(class_entry, $ nameCode, &const_ {$ constName }_value, " . $ this ->getFlagsAsString () . ", NULL); \n" ;
1690
1629
$ code .= "\tzend_string_release(const_ {$ constName }_name); \n" ;
1691
1630
1692
1631
return $ code ;
@@ -1785,7 +1724,7 @@ public function getDeclaration(): string {
1785
1724
if ($ this ->defaultValue === null ) {
1786
1725
$ defaultValue = null ;
1787
1726
} else {
1788
- $ defaultValue = $ this ->evaluateValue ($ defaultValueConstant );
1727
+ $ defaultValue = $ this ->evaluateValue ($ this -> defaultValue , $ defaultValueConstant );
1789
1728
}
1790
1729
1791
1730
if ($ defaultValueConstant ) {
0 commit comments