See also and Constructors and Destructors Static Methods Note that classes with methods bearing the class name, but inside a namespace are not following this convention, as this is not breaking backward compatibility. Having this old style constructor may bring in confusion, unless you are also supporting old time PHP 4. This is no more the case in PHP 5, which relies on _construct() to do so. You should always use _construct() in new code. The manual issues a warning about this syntax : Old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. PHP classes used to have the method bearing the same name as the class acts as the constructor. See also and Static Keyword Old Style Constructor Note that this analysis reports all static method call made on a non-static method,Įven within the same class or class hierarchy. It is recommended to update this situation : make the method actually static, or use it only PHP will not check those calls at compile time, It is a bad idea to call non-static method 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. PHP 7.0, and more recent versions, yield a deprecated error : Non-static method A::B() should not be called statically. Then, one may call them without instantiating the object. Static methods have to be declared as such (using the static keyword). See also Visibility and Understanding The Concept Of Visibility In Object Oriented PHP Non Static Methods Called In A Static Traits, classes and interfaces are checked. The PHP 4 var keyword is counted as undefined. It should at least be mentioned as public, or may be reviewed as protected or private.Ĭlass constants support also visibility since PHP 7.1.įinal, static and abstract are not counted as visibility. Some classes elements (property, method, constant) are missing their explicit visibility.īy default, it is public. _construct and _destruct are omitted here, as they are routinely used to create and destroy objects. This is possibly dead code.Įmpty classes are sometimes used to group classes an interface may be used here for the same purpose, without inserting an extra level in the class hierarchy.Ĭlasses that are directly derived from an exception are omitted. See also PHP Constants and PHP OOP Constants Empty ClassesĬlasses that do no define anything at all : no property, method nor constant. List of all classes, as defined in the application. List of indexes used when manipulating PHP arrays in the code. Multiple identical keys (automated version) Multiple identical keys (sneaky version) Indexes that are defined multiple times in the same array. See also Type array and Using Multidimensional Arrays in PHP Multiple Index Definition They are indeed distinct, but may lead to confusion. In fact, null is turned into an empty string, booleans are turned into an integer, and real numbers are truncated (not rounded). Indexes should not be defined with different types than int or string.Īrray indices only accept integers and strings, so any other type of literal is reported. If it is used to type cast a value to integer, then casting with (int) is clearer. Īdding zero is also reported when the zero is a defined constants. It is recommended to make the cast explicit with (int). This analysis also report using + with data containers, which triggers an automated conversion to integer. Besides, when one of the argument is an integer, PHP triggers a cast to integer. Īdding 0 is useless, as 0 is the neutral element for addition.
0 Comments
Leave a Reply. |