Month: January 2014
-
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…
-
Use of mysql_connect in WordPress
Take a look at this code, found inside a PHP example: This looks familiar, it’s a basic MySQL query example, found on a University of Minnesota Morris server. But what’s wrong with it? The General WordPress rule for mysql_connect: When making an SQL query in a WordPress environment, use the WPDB class, do not use mysql_connect…
-
&$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…