Skip to content

Commit

Permalink
bug #4541 Fix constant() behavior when used with ?? (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Fix constant() behavior when used with ??

The fix is broader than just this bug. Basically, it happens when we clone a Node for which an referenced Node will be modified later on.

Commits
-------

a998723 Fix constant() behavior when used with ??
  • Loading branch information
fabpot committed Jan 14, 2025
2 parents 65fa0c6 + a998723 commit 6513bc4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 3.19.0 (2025-XX-XX)

* Fix `constant()` behavior when used with `??`
* Add the `invoke` filter
* Make `{}` optional for the `types` tag
* Add `LastModifiedExtensionInterface` and implementation in `AbstractExtension` to track modification of runtime classes
Expand Down
7 changes: 7 additions & 0 deletions src/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ public function __toString()
return $repr;
}

public function __clone()
{
foreach ($this->nodes as $name => $node) {
$this->nodes[$name] = clone $node;
}
}

/**
* @return void
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/functions/constant.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
{{ constant('DATE_W3C') == expect ? 'true' : 'false' }}
{{ constant('ARRAY_AS_PROPS', object) }}
{{ constant('class', object) }}
{{ constant('ARRAY_AS_PROPS', object) ?? 'KO' }}
--DATA--
return ['expect' => DATE_W3C, 'object' => new \ArrayObject(['hi'])]
--EXPECT--
true
2
ArrayObject
2

0 comments on commit 6513bc4

Please sign in to comment.