Debunking The Myth Of Static Classes, Methods and Variables

Devin Dixon
Helium MVC
4 min readDec 12, 2018

--

Urban Legends and myths. It starts with Santa Claus when we are children to when we become adults and believe in the 5-second rule (some readers will die by it regardless of what science says). Myths proliferate into programming as well, including languages like PHP.

One such myth is the double vs single quotes in performance, which has been disproven many times. Another myth is the use of static methods is bad when rather the approach is misunderstood. Below are going over common misconceptions of using static methods in PHP, along with the real pros and cons.

Does Not Support Inheritance

FALSE. In PHP, static methods and variables have the same visibility operators as methods and variables instances do. This means public, private and protected act the same. For example:

class Parent {
public static $var1 = ‘ABC’;
protected static $var2 = ‘123’; private static $var3 =’DoeRaeMee’; public static function getChild() {
return self::$var2;
}
}

Extend our example parent class to a child:

class Child extends Parent {}

--

--