This PR was merged into the 3.x branch.
Discussion
----------
Support short-circuiting in null-safe operator chains
This PR adds short-circuiting for null-safe operator chains, using the same rules as PHP, `PropertyAccess`, and the `ExpressionLanguage`.
Previously, only the immediate null-safe access was guarded. With this change, as soon as a `null` is encountered at a null-safe access, the rest of the chain is skipped.
My approach was to move the null check outside of the `getAttribute()` calls so the expression can immediately return `null`, eg:
```twig
foo?.bar.baz
```
Before:
```php
yield $this->env
->getRuntime('Twig\Runtime\EscaperRuntime')
->escape(
CoreExtension::getAttribute(
$this->env,
$this->source,
(
null === (
$_v0 = (
isset($context['foo']) || array_key_exists('foo', $context)
? $context['foo']
: throw new RuntimeError('Variable "foo" does not exist.', 3, $this->source)
)
)
? null
: CoreExtension::getAttribute(
$this->env,
$this->source,
$_v0,
'bar',
[],
'any',
false,
false,
false,
3
)
),
'baz',
[],
'any',
false,
false,
false,
3
),
'html',
null,
true
);
```
Now:
```php
yield $this->env
->getRuntime('Twig\Runtime\EscaperRuntime')
->escape(
(
null === (
$_v0 = (
isset($context['foo']) || array_key_exists('foo', $context)
? $context['foo']
: throw new RuntimeError('Variable "foo" does not exist.', 3, $this->source)
)
)
? null
: CoreExtension::getAttribute(
$this->env,
$this->source,
CoreExtension::getAttribute(
$this->env,
$this->source,
$_v0,
'bar',
[],
'any',
false,
false,
false,
3
),
'baz',
[],
'any',
false,
false,
false,
3
)
),
'html',
null,
true
);
```
Commits
-------
d56e8e2dba Support short-circuiting in null-safe operator chains
This PR was merged into the 3.x branch.
Discussion
----------
Add support for renaming variables in object destructuring
Closes#4747
Commits
-------
3cc1b5233c Add support for renaming variables in object destructuring
This PR was merged into the 3.x branch.
Discussion
----------
[Doc] Fix intro for operator precedence table ?
The table introductory paragraph says operator with lowest precedence are listed first ( I assume it means "listed first in the operator table" ).
However, the table starts with a precedence of 500, which seems to be the highest.
Am I completely misreading this ?
Commits
-------
26a12f73f2 Fix intro for operator precedence table ?
This PR was merged into the 3.x branch.
Discussion
----------
Update .gitattributes to remove splitsh.json
- Updated .gitattributes to remove splitsh.json
Commits
-------
79aecfbae0 Update .gitattributes to remove splitsh.json
This PR was merged into the 3.x branch.
Discussion
----------
Add a not about the return value of destructuring
Commits
-------
c38868cdd0 Add a not about the return value of destructuring
This PR was merged into the 3.x branch.
Discussion
----------
Fix null-safe operator test
Noticed this while working on #4748.
Without `strict_variables`, the tests always pass, even when the null-safe operator is not used.
Commits
-------
a16ac6bd35 Fix null-safe operator test
This PR was merged into the 3.x branch.
Discussion
----------
Add support for object and mapping destructuring
Refs https://github.com/twigphp/Twig/issues/3399
Commits
-------
8a0f8acbdf Add support for object and mapping destructuring
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Assignment operator array destructuring
Follow-up to the introduction of the new = operator, array destructuring.
Refs #3399
Commits
-------
bb99af3b39 Assignment operator array destructuring
This PR was merged into the 3.x branch.
Discussion
----------
Fix grammar and spelling mistakes in documentation
Commits
-------
77cd2fd9f7 Fix grammar and spelling mistakes in documentation
This PR was merged into the 3.x branch.
Discussion
----------
Tweak null-safe operator implementation
Follow-up for #4717
Commits
-------
6904954165 Tweak null-safe operator implementation
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Add null-safe operator
Adds native support for Twig’s null-safe `?.` operator so templates can traverse objects and arrays without defensive plumbing: `{{ user?.address?.city }}` now renders the value when present and stays silent when any hop is `null`.
`?.` reuses the existing `GetAttrExpression` operator, so it should have otherwise the same precedence and behavior as `.`.
Usage cases can be found in the tests:
https://github.com/twigphp/Twig/blob/7d98d45f58df040f41a81f7f8d4cce6c42be781e/tests/ExpressionParserTest.php#L304-L343
Tests cover both the rendered output and the generated PHP.
Let me know if any tests are missing or if the implementation should be done any other way.
Commits
-------
263c04fd1f Add null-safe operator
This PR was merged into the 3.x branch.
Discussion
----------
Update u.rst to clarify truncate method's third argument behavior
Current wording "to preserve whole words" suggests setting the argument to ``true`` preserves words. However, the parameter is ``$cut`` (defaults to ``true`` for cutting at exact length), and ``false`` is required to preserve whole words.
Commits
-------
28c2606be7 Update u.rst to clarify truncate method's third argument behavior
This PR was merged into the 3.x branch.
Discussion
----------
Fix documentation for getOperators()
Closes#4710
Commits
-------
ae51f93f70 Fix documentation for getOperators()
This PR was merged into the 3.x branch.
Discussion
----------
bump version
#4736 added new operators thus require the minor version to be increased
Commits
-------
55cb67f87d bump version
Current wording "to preserve whole words" suggests setting the argument to ``true`` preserves words. However, the parameter is ``$cut`` (defaults to ``true`` for cutting at exact length), and ``false`` is required to preserve whole words.
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Enhance enum.rst with dynamic case example
Added example for dynamic enum case display.
Commits
-------
bcc5ffc301 Enhance enum.rst with dynamic case example
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Update extends.rst
Semantically correct HTML elements instead of `<div>`itis
Commits
-------
5b63d90bfb Update extends.rst