diff --git a/components/expression_language.rst b/components/expression_language.rst index fa07903bbb7..3d8f3840e52 100644 --- a/components/expression_language.rst +++ b/components/expression_language.rst @@ -80,15 +80,10 @@ The main class of the component is Null Coalescing Operator ........................ -This is the same as the PHP `null-coalescing operator`_, which combines -the ternary operator and ``isset()``. It returns the left hand-side if it exists -and it's not ``null``; otherwise it returns the right hand-side. Note that you -can chain multiple coalescing operators. - -* ``foo ?? 'no'`` -* ``foo.baz ?? 'no'`` -* ``foo[3] ?? 'no'`` -* ``foo.baz ?? foo['baz'] ?? 'no'`` +.. note:: + + This content has been moved to the ref:`null coalescing operator ` + section of ExpressionLanguage syntax reference page. Parsing and Linting Expressions ............................... diff --git a/configuration/micro_kernel_trait.rst b/configuration/micro_kernel_trait.rst index 179dc6da2d4..cb47a901859 100644 --- a/configuration/micro_kernel_trait.rst +++ b/configuration/micro_kernel_trait.rst @@ -226,6 +226,7 @@ Now it looks like this:: use App\DependencyInjection\AppExtension; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; + use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; diff --git a/controller.rst b/controller.rst index 03ca32c6553..c44f0dafdac 100644 --- a/controller.rst +++ b/controller.rst @@ -371,7 +371,7 @@ attribute, arguments of your controller's action can be automatically fulfilled: // ... public function dashboard( - #[MapQueryParameter(filter: \FILTER_VALIDATE_REGEXP, options: ['regexp' => '/^\w++$/'])] string $firstName, + #[MapQueryParameter(filter: \FILTER_VALIDATE_REGEXP, options: ['regexp' => '/^\w+$/'])] string $firstName, #[MapQueryParameter] string $lastName, #[MapQueryParameter(filter: \FILTER_VALIDATE_INT)] int $age, ): Response diff --git a/reference/formats/expression_language.rst b/reference/formats/expression_language.rst index 7daa4c98957..e0e0e258079 100644 --- a/reference/formats/expression_language.rst +++ b/reference/formats/expression_language.rst @@ -94,6 +94,8 @@ JavaScript:: This will print out ``Hi Hi Hi!``. +.. _component-expression-null-safe-operator: + Null-safe Operator .................. @@ -109,6 +111,25 @@ operator):: $expressionLanguage->evaluate('fruit?.color', ['fruit' => '...']) $expressionLanguage->evaluate('fruit?.getStock()', ['fruit' => '...']) +.. _component-expression-null-coalescing-operator: + +Null-Coalescing Operator +........................ + +It returns the left-hand side if it exists and it's not ``null``; otherwise it +returns the right-hand side. Expressions can chain multiple coalescing operators: + +* ``foo ?? 'no'`` +* ``foo.baz ?? 'no'`` +* ``foo[3] ?? 'no'`` +* ``foo.baz ?? foo['baz'] ?? 'no'`` + +.. note:: + + The main difference with the `null-coalescing operator in PHP`_ is that + ExpressionLanguage will throw an exception when trying to access a + non-existent variable. + .. _component-expression-functions: Working with Functions @@ -404,6 +425,12 @@ Ternary Operators * ``foo ?: 'no'`` (equal to ``foo ? foo : 'no'``) * ``foo ? 'yes'`` (equal to ``foo ? 'yes' : ''``) +Other Operators +~~~~~~~~~~~~~~~ + +* ``?.`` (:ref:`null-safe operator `) +* ``??`` (:ref:`null-coalescing operator `) + Built-in Objects and Variables ------------------------------ @@ -414,3 +441,5 @@ expressions (e.g. the request, the current user, etc.): * :doc:`Variables available in security expressions `; * :doc:`Variables available in service container expressions `; * :ref:`Variables available in routing expressions `. + +.. _`null-coalescing operator in PHP`: https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce