This PR was squashed before being merged into the 4.x branch.
Discussion
----------
Simplify generated code by using named arguments
Commits
-------
bce22e4c Use named arguments
a64561b4 Simplify code
This PR was squashed before being merged into the 4.x branch.
Discussion
----------
Use PHP 8 features
Commits
-------
be67e969 Use str_* when possible
0668be9e Use arrow function
06d9fc6a Use is_countable()
89d37cd5 Use get_debug_type()
308aa5ba Remove usage of list()
a42eba63 Use match instead of switch
fed8dd10 Use ::class
This PR was squashed before being merged into the 4.x branch.
Discussion
----------
Remove obsolete code
Commits
-------
b9cf29d5 Remove obsolete code
583d7b2d Remove hack to inline throwing an exception
3d5ad9ac Remove obsolete code
3472ae12 Simplify code
This PR was squashed before being merged into the 4.x branch.
Discussion
----------
[4.x] Bump to PHP 8.2
Commits
-------
bcfe41ef Remove obsolete docs
5dc2ba92 Remove tests on non-supported PHP versions
f930a284 Bump to 4.0 and require PHP 8.2
This PR was submitted for the 3.x branch but it was merged into the 2.x branch instead.
Discussion
----------
update Blackfire documentation URL
Update Blackfire documentation's URL in README file
Commits
-------
ed2cfbd6 update Blackfire documentation URL
This PR was merged into the 3.x branch.
Discussion
----------
Fix timezone fallback to CoreExtension in IntlExtension
This is probably a regression from #3844
Refer to my comment on the original MR: https://github.com/twigphp/Twig/pull/3844#issuecomment-1792464040
Commits
-------
144c4dac Fix timezone fallback to CoreExtension in IntlExtension
This PR was merged into the 3.x branch.
Discussion
----------
Minor rename of Sandbox test: functions->methods
Commits
-------
62732646 Minor rename of SandboxTest functions->methods
This PR was merged into the 3.x branch.
Discussion
----------
Removed duplicate sentence in macro scoping
Commits
-------
73f5cad8 Remove duplicate sentence in macro scoping
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Catch errors thrown during template rendering
Some errors, like not providing a function the proper number of arguments or division by zero, extend from `\Error` rather than `\Exception`. This PR catches these types of errors during template rendering and throws a `RuntimeError` in order to provide better debugging information.
Commits
-------
85bf01b4 Catch errors thrown during template rendering
This PR was merged into the 3.x branch.
Discussion
----------
Add `@codeCoverageIgnore` to untestable compiled methods
I've been experimenting with adding my compiled templates to my code coverage reports and it works largely as expected. Templates that get executed return percentages accurate to the number of lines the tests actually cover. The only exception are the "meta" methods on the compiled template that aren't necessarily called by the tests.
This PR adds ``@codeCoverageIgnore`` comments to the compiled template for all non-display methods so the coverage report only lists lines from `doDisplay`.
I'm assuming that I will need to update some of the Twig tests to account for these new comments, but am curious if you'd be open to this change.
An example screenshot below. The last line shows line 46 out of the compiled template is never executed. The compiled template's `getDebugInfo` even correctly informs me that line 46 maps to line 4 in my `.twig` so I'll work on updating the line numbering next.

Commits
-------
1cf610bd Add `@codeCoverageIgnore` to untestable compiled methods
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Fix IntlExtension::formatDateTime use of date formatter prototype
See https://github.com/twigphp/intl-extra/pull/6 for more details
Commits
-------
c75762c3 Fix IntlExtension::formatDateTime use of date formatter prototype
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
Fix premature loop exit in Security Policy lookup of allowed methods/properties
The current security policy logic exits too soon when checking permissions for allowed classes and their methods/properties, causing false negatives in situations involving classes related by inheritance.
Consider the following configuration:
```
'methods' => [
'App\BasicCollection' => ['sortAlphabetically'],
'App\AdvancedCollection'=> ['sortByTimestamp'],
],
```
where `AdvancedCollection` is a subclass of `BasicCollection`, and `mylist` is an instance of `AdvancedCollection`
If you try to call `{{ mylist.sortByTimestamp() }}`, the current code will first match `mylist` against `App\BasicCollection`. Since `sortByTimestamp` is not an allowed method for `App\BasicCollection`, the code will exit the loop and incorrectly deny access. It will never get to checking `App\AdvancedCollection`.
Note that reordering classes in the config can't solve this issue. If you flipped the order, then it would fail for `{{ mylist.sortAlphabetically() }}` instead.
This pull request fixes the issue by only exiting the loop early when both the class and method/property match.
Commits
-------
5e1838db Fix premature loop exit in Security Policy lookup of allowed methods/properties
This PR was merged into the 3.x branch.
Discussion
----------
Compile Elvis operator into Elvis operator `?:`
When using ternary operator without "then" part, the "condition" part is evaluated twice, which is inconsistent with how PHP works.
The Twig template `A ?: B` is currently compiled as `A ? A : B` in PHP. This PR change it to `A ?: B`.
If `A` is a complex expression, it improves performance to only execute the expression once.
If `A` is has a side effect (like updating a variable), the expression being executed twice could result in a bug. ([example in PHP](https://3v4l.org/LWZLR))
Example with ``@WebProfiler`/Collector/form.html.twig` [line 9](https://github.com/symfony/symfony/blob/e6d1ed4edb5ae197ec7d25ddaf64cfa456229504/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig#L9) (see deep [diff](https://www.diffchecker.com/jOm3dE13/))
```twig
{{ collector.data.nb_errors ?: collector.data.forms|length }}
```
Previous compilation:
```php
echo twig_escape_filter($this->env, (((isset($context["error_count"]) || array_key_exists("error_count", $context) ? $context["error_count"] : (function () { throw new RuntimeError('Variable "error_count" does not exist.', 9, $this->source); })())) ? ((isset($context["error_count"]) || array_key_exists("error_count", $context) ? $context["error_count"] : (function () { throw new RuntimeError('Variable "error_count" does not exist.', 9, $this->source); })())) : (twig_get_attribute($this->env, $this->source, (isset($context["collector"]) || array_key_exists("collector", $context) ? $context["collector"] : (function () { throw new RuntimeError('Variable "collector" does not exist.', 9, $this->source); })()), "countDefines", [], "any", false, false, false, 9))), "html", null, true);
```
After this change:
```php
echo twig_escape_filter($this->env, ((isset($context["error_count"]) || array_key_exists("error_count", $context) ? $context["error_count"] : (function () { throw new RuntimeError('Variable "error_count" does not exist.', 9, $this->source); })()) ?: twig_get_attribute($this->env, $this->source, (isset($context["collector"]) || array_key_exists("collector", $context) ? $context["collector"] : (function () { throw new RuntimeError('Variable "collector" does not exist.', 9, $this->source); })()), "countDefines", [], "any", false, false, false, 9)), "html", null, true);
```
Commits
-------
fb0d7495 Compile Elvis operator with Elvis operator