wordpress-handbook
wordpress-handbook copied to clipboard
Add class organization in PHP standards
Add example and explanation about visibility ordering of methods and properties in classes like described here: https://stackoverflow.com/a/310967
Proposed organization within a class
class Class_Name {
const CONSTANT_NAME = '...';
public $public_property;
protected $protected_property;
private $private_property;
public function __construct() {...}
public function public_method() {...};
public static function public_static_method() {...};
protected static function protected_static_method() {...};
private static function private_static_method() {...};
public abstract function public_abstract_method();
protected abstract function protected_abstract_method();
private abstract function private_abstract_method();
protected function protected_method() {...};
private function private_method() {...};
}
Constants first, then properties (avoid using public properties), after that a class constructor and destructor (rarely used in WP context), public methods, static (avoid if possible) and abstract methods, then protected and private methods (internals).
Could go here: https://infinum.com/handbook/books/wordpress/coding-standards/php-coding-standards/naming#class-method-visibility