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