PHP Class Variables and Methods

The class variable is declared outside of all other methods. To reference the variable use the following syntax.


Below is a brief example on how this would be used. The class variable is defined outside any functions, the variable is then set inside the constructor.

class testClass
protected testVariable
public function __construct()
$this->testVariable = 0;

This same syntax is the same for referencing functions within the same class.

Note: When calling the variable do not prefix with the $ sign as you would in other situations.