.. _classes-shoulduseself: .. _could-use-self: Could Use self ++++++++++++++ ``self`` keyword refers to the current class, or any of its parents. Using it is just as fast as the full class name, it is as readable and it is will not be changed upon class or namespace change. It is also routinely used in traits : there, ``self`` represents the class in which the trait is used, or the trait itself. .. code-block:: php See also `Scope Resolution Operator (::) `_. Connex PHP features ------------------- + `self `_ + `class `_ Suggestions ___________ * Replace the explicit name with ``self`` Specs _____ +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Short name | Classes/ShouldUseSelf | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`Changed Behavior `, :ref:`Class Review `, :ref:`Suggestions ` | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 0.8.4 | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Instant (5 mins) | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Precision | High | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Examples | :ref:`case-wordpress-classes-shoulduseself`, :ref:`case-livezilla-classes-shoulduseself` | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+