I expected the following to work but it doesn\'t seem to.
In PHP, static and const are two different things.
const denotes a class constant. They're different than normal variables as they don't have the '$' in front of them, and can't have any visibility modifiers (public, protected, private) before them. Their syntax:
class Test
{
const INT = "/^\d+$/";
}
Because they're constant, they're immutable.
Static denotes data that is shared between objects of the same class. This data can be modified. An example would be a class that keeps track of how many instances are in play at any one time:
class HowMany
{
private static $count = 0;
public function __construct()
{
self::$count++;
}
public function getCount()
{
return self::$count;
}
public function __destruct()
{
self::$count--;
}
}
$obj1 = new HowMany();
$obj2 = new HowMany();
echo $obj1->getCount();
unset($obj2);
echo $obj1->getCount();