@@ -2358,11 +2358,14 @@ private function __construct($value, SimpleType $type, Expr $expr, array $origin
2358
2358
$ this ->isUnknownConstValue = $ isUnknownConstValue ;
2359
2359
}
2360
2360
2361
- public function initializeZval (string $ zvalName ): string
2361
+ public function initializeZval (string $ zvalName, bool $ alreadyExists = false , string $ forStringDef = '' ): string
2362
2362
{
2363
2363
$ cExpr = $ this ->getCExpr ();
2364
2364
2365
- $ code = "\tzval $ zvalName; \n" ;
2365
+ $ code = '' ;
2366
+ if (!$ alreadyExists ) {
2367
+ $ code = "\tzval $ zvalName; \n" ;
2368
+ }
2366
2369
2367
2370
if ($ this ->type ->isNull ()) {
2368
2371
$ code .= "\tZVAL_NULL(& $ zvalName); \n" ;
@@ -2382,8 +2385,11 @@ public function initializeZval(string $zvalName): string
2382
2385
if ($ cExpr === '"" ' ) {
2383
2386
$ code .= "\tZVAL_EMPTY_STRING(& $ zvalName); \n" ;
2384
2387
} 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" ;
2387
2393
}
2388
2394
} elseif ($ this ->type ->isArray ()) {
2389
2395
if ($ cExpr == '[] ' ) {
@@ -2821,7 +2827,8 @@ private function getClassConstDeclaration(EvaluatedValue $value, array $allConst
2821
2827
{
2822
2828
$ constName = $ this ->name ->getDeclarationName ();
2823
2829
2824
- $ zvalCode = $ value ->initializeZval ("const_ {$ constName }_value " , $ allConstInfos );
2830
+ // TODO $allConstInfos is unused
2831
+ $ zvalCode = $ value ->initializeZval ("const_ {$ constName }_value " );
2825
2832
2826
2833
$ code = "\n" . $ zvalCode ;
2827
2834
@@ -3378,9 +3385,11 @@ public function generateCode(string $invocation, string $nameSuffix, array $allC
3378
3385
}
3379
3386
if ($ initValue === '' ) {
3380
3387
$ 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
+ );
3384
3393
} else {
3385
3394
$ code .= $ initValue ;
3386
3395
}
0 commit comments