Skip to content

[ExpressionLanguage] Fix coalescing operator deep nested properties #47446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public function evaluate(array $functions, array $values)
{
switch ($this->attributes['type']) {
case self::PROPERTY_CALL:
if ($this->nodes['node'] instanceof GetAttrNode) {
$this->nodes['node']->attributes['is_null_coalesce'] = $this->attributes['is_null_coalesce'];
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be $this->nodes['node']->attributes['is_null_coalesce'] = $this->nodes['node']->attributes['is_null_coalesce'] || $this->attributes['is_null_coalesce']; ?

Copy link
Contributor Author

@mytuny mytuny Sep 12, 2022

Choose a reason for hiding this comment

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

shouldn't this be $this->nodes['node']->attributes['is_null_coalesce'] = $this->nodes['node']->attributes['is_null_coalesce'] || $this->attributes['is_null_coalesce']; ?

@stof This will introduce a regression when we have a mixed chaining between different types of nodes (not only GetAttrNode).

Choose a reason for hiding this comment

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

Suggested change
$this->nodes['node']->attributes['is_null_coalesce'] = $this->attributes['is_null_coalesce'];
$this->nodes['node']->attributes['is_null_coalesce'] = $this->attributes['is_null_coalesce'] ?? false;

}

$obj = $this->nodes['node']->evaluate($functions, $values);
if (null === $obj && ($this->nodes['attribute']->isNullSafe || $this->attributes['is_null_coalesce'])) {
$this->attributes['is_short_circuited'] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public function bar()

yield ['foo.bar ?? "default"', null];
yield ['foo.bar.baz ?? "default"', (object) ['bar' => null]];
yield ['foo.bar.baz.bam ?? "default"', (object) ['bar' => null]];
yield ['foo.bar ?? foo.baz ?? "default"', null];
yield ['foo[0] ?? "default"', []];
yield ['foo["bar"] ?? "default"', ['bar' => null]];
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy