.. _classes-nonstaticmethodscalledstatic: .. _non-static-methods-called-in-a-static: Non Static Methods Called In A Static +++++++++++++++++++++++++++++++++++++ `Static `_ methods have to be declared as such (using the `static `_ keyword). Then, one may call them without instantiating the object. PHP 7.0, and more recent versions, yield a deprecated `error `_ : ``Non-`static `_ method A\:\:B() should not be called statically``. PHP 5 and older doesn't check that a method is `static `_ or not : at any point, the code may call one method statically. It is a bad idea to call non-`static `_ method statically. Such method may make use of special variable `$this `_, which will be undefined. PHP will not check those calls at compile time, nor at running time. It is recommended to update this situation : make the method actually `static `_, or use it only in object context. Note that this analysis reports all `static `_ method call made on a non-`static `_ method, even within the same class or class hierarchy. PHP silently accepts `static `_ call to any in-family method. .. code-block:: php See also `Static Keyword `_. Related PHP errors ------------------- + `0 `_ Connex PHP features ------------------- + `static `_ Suggestions ___________ * Call the method the correct way * Define the method as static Specs _____ +--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Short name | Classes/NonStaticMethodsCalledStatic | +--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`CE `, :ref:`CI-checks `, :ref:`Changed Behavior `, :ref:`CompatibilityPHP53 `, :ref:`CompatibilityPHP54 `, :ref:`CompatibilityPHP55 `, :ref:`CompatibilityPHP56 ` | +--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 0.8.4 | +--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Precision | Medium | +--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Examples | :ref:`case-dolphin-classes-nonstaticmethodscalledstatic`, :ref:`case-magento-classes-nonstaticmethodscalledstatic` | +--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Community Edition `_, `Exakat Cloud `_ | +--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+