Execute PHP class without `new` keyword?
I'm using the keyword new
, so I was surprised to find that the following also works for instantiation.
class MyClass
{
const CONSTANT = 'constant value';
function showConstant() {
echo self::CONSTANT;
}
}
// $classname = new MyClass;
$classname = "MyClass";
echo $classname::CONSTANT;
I cannot find any documentation related to this online. Can anyone help me?
+3
source to share