.. _functions-noliteralforreference: .. _no-literal-for-reference: No Literal For Reference ++++++++++++++++++++++++ Method arguments and return values may be by reference. Then, they need to be a valid variable. Objects are always passed by reference, so there is no need to explicitly declare it. Expressions, including ternary operator, produce value, and can't be used by reference directly. This is also the case for expression that include one or more reference. Wrongly passing a value as a reference leads to a PHP Notice. .. code-block:: php See also `References `_. Related PHP errors ------------------- + `Cannot pass parameter %s by reference `_ + `%s(): Argument #%s (%s) must be passed by reference, value given `_ + `Only variable references should be returned by reference `_ Connex PHP features ------------------- + `reference `_ + `literal `_ Suggestions ___________ * Remove the reference in the method signature (argument or return value) * Make the argument an object, by using a typehint (non-scalar) * Put the value into a variable prior to call (or return) the method Specs _____ +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Short name | Functions/NoLiteralForReference | +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`CE `, :ref:`CI-checks `, :ref:`Changed Behavior ` | +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 1.9.5 | +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Precision | High | +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Community Edition `_, `Exakat Cloud `_ | +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+