@@ -2358,11 +2358,14 @@ private function __construct($value, SimpleType $type, Expr $expr, array $origin
23582358 $ this ->isUnknownConstValue = $ isUnknownConstValue ;
23592359 }
23602360
2361- public function initializeZval (string $ zvalName ): string
2361+ public function initializeZval (string $ zvalName, bool $ alreadyExists = false , string $ forStringDef = '' ): string
23622362 {
23632363 $ cExpr = $ this ->getCExpr ();
23642364
2365- $ code = "\tzval $ zvalName; \n" ;
2365+ $ code = '' ;
2366+ if (!$ alreadyExists ) {
2367+ $ code = "\tzval $ zvalName; \n" ;
2368+ }
23662369
23672370 if ($ this ->type ->isNull ()) {
23682371 $ code .= "\tZVAL_NULL(& $ zvalName); \n" ;
@@ -2382,8 +2385,11 @@ public function initializeZval(string $zvalName): string
23822385 if ($ cExpr === '"" ' ) {
23832386 $ code .= "\tZVAL_EMPTY_STRING(& $ zvalName); \n" ;
23842387 } else {
2385- $ code .= "\tzend_string * {$ zvalName }_str = zend_string_init( $ cExpr, strlen( $ cExpr), 1); \n" ;
2386- $ code .= "\tZVAL_STR(& $ zvalName, {$ zvalName }_str); \n" ;
2388+ if ($ forStringDef === '' ) {
2389+ $ forStringDef = "{$ zvalName }_str " ;
2390+ }
2391+ $ code .= "\tzend_string * $ forStringDef = zend_string_init( $ cExpr, strlen( $ cExpr), 1); \n" ;
2392+ $ code .= "\tZVAL_STR(& $ zvalName, $ forStringDef); \n" ;
23872393 }
23882394 } elseif ($ this ->type ->isArray ()) {
23892395 if ($ cExpr == '[] ' ) {
@@ -2821,7 +2827,8 @@ private function getClassConstDeclaration(EvaluatedValue $value, array $allConst
28212827 {
28222828 $ constName = $ this ->name ->getDeclarationName ();
28232829
2824- $ zvalCode = $ value ->initializeZval ("const_ {$ constName }_value " , $ allConstInfos );
2830+ // TODO $allConstInfos is unused
2831+ $ zvalCode = $ value ->initializeZval ("const_ {$ constName }_value " );
28252832
28262833 $ code = "\n" . $ zvalCode ;
28272834
@@ -3378,9 +3385,11 @@ public function generateCode(string $invocation, string $nameSuffix, array $allC
33783385 }
33793386 if ($ initValue === '' ) {
33803387 $ value = EvaluatedValue::createFromExpression ($ arg ->value , null , null , $ allConstInfos );
3381- $ zvalName = "attribute_ {$ escapedAttributeName }_ {$ nameSuffix }_arg $ i " ;
3382- $ code .= $ value ->initializeZval ($ zvalName );
3383- $ code .= "\tZVAL_COPY_VALUE(&attribute_ {$ escapedAttributeName }_ {$ nameSuffix }->args[ $ i].value, & $ zvalName); \n" ;
3388+ $ code .= $ value ->initializeZval (
3389+ "attribute_ {$ escapedAttributeName }_ {$ nameSuffix }->args[ $ i].value " ,
3390+ true ,
3391+ "attribute_ {$ escapedAttributeName }_ {$ nameSuffix }_arg {$ i }_str "
3392+ );
33843393 } else {
33853394 $ code .= $ initValue ;
33863395 }
0 commit comments