83 Commits

Author SHA1 Message Date
Fabien Potencier f640320202 Merge branch '3.x' into 4.x
* 3.x: (26 commits)
  Remove the documentation comments compilation overhead
  Clarify source function trust requirements
  Throw on PCRE errors in the matches operator
  Document that reusing a non-rewindable iterator after destructuring is unsupported
  Release destructuring temporaries after assignment
  Deprecate prefixed macro definedness checks
  Fix duplicate macro deprecation wording
  Throw when list formatting fails
  Document that sequence destructuring consumes one value per pattern slot
  Fix the html_attr documentation about iterables in data attributes
  Warn about untrusted input with the default Tempest markdown converter
  Document that overriding MacroNode::compile() is not supported anymore
  Merge overlapping CHANGELOG entries for the destructuring fatal error fix
  Document that include_only keeps global variables available
  Remove lazy macro import resolution
  Honor date formatter prototype calendars
  Fix Stringable keys for ArrayAccess implementations
  Fix repeated object destructuring evaluation
  Restore void return type compatibility for extension points
  Reject destructuring patterns containing no variables
  ...

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	doc/filters/format_datetime.rst
#	extra/twig-extra-bundle/DependencyInjection/Compiler/MissingExtensionSuggestorPass.php
#	extra/twig-extra-bundle/DependencyInjection/TwigExtraExtension.php
#	extra/twig-extra-bundle/TwigExtraBundle.php
#	src/MacroNamespace.php
#	src/Node/MacrosNode.php
#	src/Parser.php
#	src/Test/IntegrationTestCase.php
#	src/Test/NodeTestCase.php
#	tests/CallMacroTest.php
#	tests/ExpressionParserTest.php
#	tests/Fixtures/macros/duplicate_definition.legacy.test
#	tests/Node/MacrosTest.php
#	tests/ParserTest.php
2026-08-29 00:25:20 +02:00
Fabien Potencier 609376f491 Fix repeated object destructuring evaluation 2026-08-27 07:37:11 +02:00
Fabien Potencier a3a318face Reject destructuring patterns containing no variables 2026-08-27 07:18:49 +02:00
Fabien Potencier a2b023397e Fix an empty destructuring pattern triggering a PHP fatal error instead of a SyntaxError 2026-08-23 09:50:46 +02:00
Fabien Potencier d266b2df7f Merge branch '3.x' into 4.x
* 3.x:
  Clarify the security scope for untrusted templates
  Normalize destructuring assignment targets
  Deprecate duplicate macro definitions

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	tests/ExpressionParserTest.php
2026-07-28 09:58:56 +02:00
Fabien Potencier 6ce5beb7c2 Normalize destructuring assignment targets 2026-07-27 18:51:15 +02:00
Fabien Potencier 5ca7debf6e Fix merge conflict resolution 2026-07-12 15:08:38 +02:00
Fabien Potencier 0b6e824ea8 Merge branch '3.x' into 4.x
* 3.x:
  Add void return type hint even in tests
  Run php-cs-fixer sequentially so the void_return src-only customiser is applied
  Fix CHANGELOG
  [Intl] Add format_list filter using PHP 8.5's IntlListFormatter

# Conflicts:
#	.github/workflows/ci.yml
#	CHANGELOG
#	extra/cssinliner-extra/Tests/LegacyFunctionsTest.php
#	extra/html-extra/Tests/CvaTest.php
#	extra/html-extra/Tests/HtmlAttrMergeTest.php
#	extra/html-extra/Tests/HtmlAttrTest.php
#	extra/html-extra/Tests/LegacyFunctionsTest.php
#	extra/inky-extra/Tests/LegacyFunctionsTest.php
#	extra/markdown-extra/Tests/FunctionalTest.php
#	extra/markdown-extra/Tests/LegacyFunctionsTest.php
#	extra/twig-extra-bundle/DependencyInjection/Compiler/MissingExtensionSuggestorPass.php
#	extra/twig-extra-bundle/DependencyInjection/TwigExtraExtension.php
#	extra/twig-extra-bundle/TwigExtraBundle.php
#	src/Extension/CoreExtension.php
#	src/Extension/EscaperExtension.php
#	src/Node/CheckSecurityCallNode.php
#	src/Node/Expression/FunctionExpression.php
#	src/Node/ModuleNode.php
#	src/Node/Node.php
#	src/Node/TypesNode.php
#	src/Resources/core.php
#	src/Resources/debug.php
#	src/Test/IntegrationTestCase.php
#	tests/CustomExtensionTest.php
#	tests/EnvironmentTest.php
#	tests/ExpressionParserTest.php
#	tests/Extension/CoreTest.php
#	tests/Extension/EscaperTest.php
#	tests/Extension/LegacyDebugFunctionsTest.php
#	tests/Extension/LegacyStringLoaderFunctionsTest.php
#	tests/Extension/SandboxStateChangeTest.php
#	tests/Extension/SandboxTest.php
#	tests/LexerTest.php
#	tests/Node/Expression/CallTest.php
#	tests/Node/Expression/ConditionalTest.php
#	tests/Node/NodeTest.php
#	tests/Resources/LegacyCoreTest.php
#	tests/TemplateTest.php
#	tests/Util/CallableArgumentsExtractorTest.php
2026-07-12 13:55:37 +02:00
Fabien Potencier 9c6d76b61c Add void return type hint even in tests 2026-07-12 13:43:08 +02:00
Fabien Potencier 82bc07bc64 Merge branch '3.x' into 4.x
* 3.x:
  Reduce memory usage of the context restoration compiled at the end of for loops
  Clarify sandbox always-allowed trust boundary
  Bump version to 3.28.0 for the always_allowed_in_sandbox feature
  Add regression tests that always-allowed callables still enforce the sandbox __toString policy on arguments
  Document the criteria for always-allowed sandbox items and list 4.0 built-ins
  Add an always_allowed_in_sandbox flag for filters, functions, and tags
  Remove issue references in tests
  Avoid allocating a normalized copy when counting newlines without carriage returns
  Report columns in syntax errors
  Track the source offset of each token

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	doc/sandbox.rst
#	src/Environment.php
#	src/Error/Error.php
#	src/Lexer.php
#	src/Node/ForNode.php
#	src/Token.php
#	src/TwigCallableInterface.php
#	tests/Extension/SandboxTest.php
#	tests/Node/ForTest.php
2026-06-06 11:03:40 +02:00
Fabien Potencier a82782ac30 Report columns in syntax errors 2026-06-05 20:28:45 +02:00
Fabien Potencier 8a4b77920a Add PHPUnit attributes alongside annotations to silence doc-comment metadata deprecations on PHPUnit 11 2026-06-03 18:26:39 +02:00
Fabien Potencier 11d5cb5bd1 Replace @dataProvider annotations with #[DataProvider] attributes 2026-05-23 11:36:24 +02:00
Fabien Potencier b8e6b314b3 Merge branch '3.x' into 4.x
* 3.x:
  fix documentation typos for singular filter arguments
  Add getOperatorTokens() to ExpressionParserInterface to separate operator token registration from parser identity
  Ensure filters/attributes aren't mistaken for operators
2026-02-25 09:40:35 +01:00
Fabien Potencier e5eb95d0d7 Add getOperatorTokens() to ExpressionParserInterface to separate operator token registration from parser identity 2026-02-24 21:13:06 +01:00
Fabien Potencier 463ef4018d Merge branch '3.x' into 4.x
* 3.x:
  Update CHANGELOG
  Add `html_attr_relaxed` escaping strategy
  re-add mixed return type
  Support short-circuiting in null-safe operator chains
  Add support for renaming variables in object destructuring
  Update .gitattributes to remove splitsh.json
  Fix intro for operator precedence table ?
2026-02-09 12:29:34 +01:00
Fabien Potencier 751a187f07 feature #4748 Support short-circuiting in null-safe operator chains (HypeMC)
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
2026-02-08 19:02:03 +01:00
Fabien Potencier 0facb551b0 Merge branch '3.x' into 4.x
* 3.x:
  Fix CS
2026-02-07 09:12:05 +01:00
Fabien Potencier 861215c507 Fix CS 2026-02-07 09:07:38 +01:00
Fabien Potencier 0222460a72 Merge branch '3.x' into 4.x
* 3.x:
  Bump version
  Add a not about the return value of destructuring
  Fix null-safe operator test
  Bump version
  Prepare the  release
  Update CHANGELOG
  Add support for object and mapping destructuring
  Rename classes
  Assignment operator array destructuring
  Fix doc notes
  Fix doc notes
  Add the = assignment operator
  Fix grammar and spelling mistakes in documentation
2026-02-06 22:45:48 +01:00
HypeMC d56e8e2dba Support short-circuiting in null-safe operator chains 2026-02-06 22:36:57 +01:00
HypeMC a16ac6bd35 Fix null-safe operator test 2026-01-25 04:57:19 +01:00
Fabien Potencier bb99af3b39 Assignment operator array destructuring 2026-01-21 08:46:28 +01:00
Fabien Potencier bfbbef05f2 Add the = assignment operator 2026-01-19 16:39:57 +01:00
Fabien Potencier e968cf6591 Merge branch '3.x' into 4.x
* 3.x:
  Tweak null-safe operator implementation
  Add null-safe operator
  Update u.rst to clarify truncate method's third argument behavior
2026-01-17 15:17:13 +01:00
Felds Liscia 263c04fd1f Add null-safe operator 2026-01-17 14:57:47 +01:00
Nicolas Grekas c649c1658b Merge branch '3.x' into 4.x
* 3.x:
  CS fixes
  Enable Fabbot as a GHA
2025-07-29 10:27:55 +02:00
Nicolas Grekas 85a4817128 CS fixes 2025-07-29 10:07:07 +02:00
Fabien Potencier 50cdb7bf4a Remove usage of @dataProvider 2025-02-26 22:01:08 +01:00
Fabien Potencier 655b00c624 Fix CS 2025-02-14 12:53:03 +01:00
Fabien Potencier 9bccdf438d Merge branch '3.x' into 4.x
* 3.x:
  Add a proper prefix spread operator
  Avoid storing expression parser instances in Node attributes
2025-02-14 12:51:14 +01:00
Fabien Potencier 3964aeba78 Add a proper prefix spread operator 2025-02-14 11:45:39 +01:00
Fabien Potencier 171262ca24 Remove deprecated code 2025-02-14 09:54:25 +01:00
Fabien Potencier 6032fd320c Merge branch '3.x' into 4.x
* 3.x:
  Fix version
  Fix CS
  Remove obsolete code
  Use generics in ExpressionParsers
  Fix precedence rules
  Add deprecation notices in CHANGELOG and docs
  Move Operators to ExpressionParsers, deprecate ExpressionParser
  Add a script to update operator precedence documentation
  Extract operators logic from ExpressionParser to their own classes
  Introduce operator classes to describe operators provided by extensions instead of arrays
  Bump version to 3.21
2025-02-14 09:08:33 +01:00
Fabien Potencier 251c0b5da9 Fix CS 2025-02-14 08:45:28 +01:00
Fabien Potencier 8ff19090f3 Fix precedence rules 2025-02-14 08:38:53 +01:00
Fabien Potencier f67078b5c4 Move Operators to ExpressionParsers, deprecate ExpressionParser 2025-02-14 08:38:53 +01:00
Fabien Potencier df877a1d53 Introduce operator classes to describe operators provided by extensions instead of arrays 2025-02-14 08:38:53 +01:00
Fabien Potencier 28246c5d4e Merge branch '3.x' into 4.x
* 3.x:
  Fixing minor typo in Update inline_css.rst
  Ignore static properties when using the dot operator
  Fix CS
  Fix constant() behavior when used with ??
  Finish the work
  fix indentation
  Apply suggestions from code review
  typo
  fix merge
  docs and changelog
  typehint instead of checkArrow
  checkArrow, typehints
  invoke filter
2025-01-24 11:32:17 +01:00
Fabien Potencier 76062c8d51 Fix CS 2025-01-19 16:54:05 +01:00
Fabien Potencier 9bcf837835 Fix test 2025-01-10 08:42:15 +01:00
Fabien Potencier ef7ade8ee3 Merge branch '3.x' into 4.x
* 3.x: (30 commits)
  Make {} optional for the types tag
  Remove the note about types mapping argument
  Add a note on the types locality
  Fix CS
  Fix typos in the docs
  Use spl_object_id() instead of spl_object_hash()
  Add `LastModifiedExtensionInterface` and implementation in `AbstractExtension` to track modification of runtime classes
  Bump version
  Optimize NameExpression compilation
  Fix typo in enum twig doc functions
  Remove dead method in ModuleNode
  Bump version
  Prepare the 3.18.0 release
  Add support for `Twig\Markup`
  Fix unary operator precedence change
  Replace Twigfiddle by the new Twig playground
  Fix MacroNode $name argument can be overridden
  Ignore exceptions from undefined handlers when using the guard tag
  [Doc] Update the docs about attribute() function
  Fix doc
  ...
2025-01-10 08:41:31 +01:00
Fabien Potencier 2cf1939d01 Fix unary operator precedence change 2024-12-28 11:29:38 +01:00
Fabien Potencier 4698d15b8e Remove obsolete code, remove deprecations 2024-10-24 08:23:21 +02:00
Fabien Potencier ef63506239 Merge branch '3.x' into 4.x
* 3.x:
  Improve ImportNode impl
  Rename Node classes related to variables
2024-10-24 07:57:29 +02:00
Fabien Potencier fc15e7ccbc Rename Node classes related to variables 2024-10-23 12:36:57 +02:00
Fabien Potencier ea0ed28111 Merge branch '3.x' into 4.x
* 3.x:
  Add support for named arguments on macro calls and dot operator arguments
  Improve deprecation messages
  Simplify expression parser code
  Refactor expression parser
  chore: fix version added
  Cleanup code
2024-10-11 11:46:56 +02:00
Fabien Potencier 223d36bbae Add support for named arguments on macro calls and dot operator arguments 2024-10-11 11:31:40 +02:00
Fabien Potencier e431a469f4 Use SpreadUnary everywhere 2024-09-11 16:24:45 +02:00
Fabien Potencier fa1c9f0bf9 Merge branch '3.x' into 4.x
* 3.x:
  Remove obsolete code
  Deprecate Environment::mergeGlobals()
  Bump version
  Prepare the 3.13.0 release
  Fix wrong format of `Environment::VERSION_ID` constant
  Fix minor things
  Fix CS
  Fix isset in ForLoopNode
  Fix iterable return type
  Improve exception expectations reliability
2024-09-07 17:03:10 +02:00