Skip to content

Conversation

arshidkv12
Copy link
Contributor

Comment on lines 90 to 104
foreach ($node->stmts as $stmt) {
if ($stmt instanceof Node\Stmt\Return_ && $stmt->expr instanceof Array_) {
$newItems = [];
foreach ($stmt->expr->items as $item) {
if ($item !== null && $item->value instanceof Node\Scalar\String_) {
$propName = $item->value->value;
$newItems[] = new ArrayItem(
new PropertyFetch(new Node\Expr\Variable('this'), $propName),
$item->value
);
}
}
$stmt->expr->items = $newItems;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use betterNodeFinder->findReturnsScoped($node) to locate returns, and apply change/validate for its values, see example

$returns = $this->betterNodeFinder->findReturnsScoped($node);
if (! $this->returnAnalyzer->hasOnlyReturnWithExpr($node, $returns)) {
return null;
}
foreach ($returns as $return) {
// we need exact string "value" return
if (! $return->expr instanceof String_ && ! $return->expr instanceof InterpolatedString) {
return null;
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check now

foreach ($return->expr->items as $item) {
if ($item !== null && $item->value instanceof Node\Scalar\String_) {
$propName = $item->value->value;
$newItems[] = new ArrayItem(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add $hasChanged = false init variable before loop, set $hasChanged = true after changed, verify $hasChanged before apply return, return null if no change

);
}
}
$return->expr->items = $newItems;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init $newItems inside inner loop, verify not empty before assign

}

}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check ! $hasChanged, return null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check now.

Copy link
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give link of example the error/deprecation notice on https://3v4l.org/ for this case?

Also probably handle __wakeup as well.

Thank you.

@arshidkv12
Copy link
Contributor Author

arshidkv12 commented Sep 3, 2025

Also probably handle __wakeup as well.

php/php-src#19435

Not implemented in PHP core yet. I think it will be added soon. I’ll add __wakeup soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants