Constant is just a constant, you can't change its value after declaring. if the property should not be changed, then a constant is the proper choice. you don't use the $ symbol to declare or use them. The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call. Note : The variable's value can not be a keyword (e.g. self, parent and static).
Static variable or method is accessible without needing an instantiation of the class. and therefore shared between all the instances of a class. if the property allowed to be changed then use static. Static variables reduce the amount of memory used by a program.
class Foo { public static $my_static = 'abc'; //static variable } echo Foo::$my_static; //output : abc
Static local variable in a function that is declared only once on the first execution of a function.
function static_test() { static $i = 0; $i++; echo "function has been called ".$i." times"; } static_test(); //function has been called 1 times static_test(); //function has been called 2 times
// Works as of PHP 5.3.0 const CONSTANT = 'Hello World'; echo CONSTANT; // Works as of PHP 5.6.0 const ANOTHER_CONST = CONSTANT.'; Goodbye World'; echo ANOTHER_CONST; const ANIMALS = array('dog', 'cat', 'bird'); echo ANIMALS[1]; // outputs "cat" // Works as of PHP 7 define('ANIMALS', array( 'dog', 'cat', 'bird' )); echo ANIMALS[1]; // outputs "cat"