Category: Hygiene
-
Calling Constructors
Take a look at this code, found inside the Jetpack Post Views plugin: Here an object is calling its own constructor. But what’s wrong with it? The General rule for calling __construct: The only occasion it is okay to call a constructor method directly, is in a child class that needs to call its parent…
-
&$this
Take a look at this code, found inside a PHP class or object: This looks familiar, and can be found in many themes and plugins. But what’s wrong with it? It’s PHP4 code in a PHP5 world. General PHP rule for add_action: When creating a callable, never use &$this, use $this instead There is almost never…