<?php
class MyClass
{
const CONSTANT = 'constant value';
function showConstant() {
echo self::CONSTANT . "\n";
}
}
echo MyClass::CONSTANT . "\n";
$classname = "MyClass";
echo $classname::CONSTANT . "\n"; // As of PHP 5.3.0
class B
{
function __construct()
{
$this->myclass = new MyClass();
$this->myclass->showConstant();
echo $this->myclass::CONSTANT;
}
}
$b = new B
?>
- Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- constant value
constant value
Deprecated: Creation of dynamic property B::$myclass is deprecated in /in/YmaHq on line 20
constant value
constant value
- Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
- constant value
constant value
constant value
constant value
- Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
- Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting ',' or ';' in /in/YmaHq on line 22
Process exited with code 255.
preferences:
288.64 ms | 402 KiB | 330 Q