3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MyClass { const MY_CONST = 'value'; // 常量 static $staticVar = 'static'; // 属性必须声明其作用域 public $property = 'public'; public $instanceProp; protected $prot = 'protected'; // 当前类和子类可访问 private $priv = 'private'; // 仅当前类可访问 // 通过 __construct 来定义构造函数 public function __construct($instanceProp) { // 通过 $this 访问当前对象 $this->instanceProp = $instanceProp; } // 方法就是类中定义的函数 public function myMethod() { print 'MyClass'; } final function youCannotOverrideMe() { } public static function myStaticMethod() { print 'I am static'; } } echo MyClass::MY_CONST; // 输出 'value'; echo MyClass::$staticVar; // 输出 'static'; MyClass::myStaticMethod(); // 输出 'I am static';
Output for 5.0.0 - 5.0.5, 5.1.1 - 7.1.0
valuestaticI am static
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/oPvvJ on line 38
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/oPvvJ on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/oPvvJ on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/oPvvJ on line 4
Process exited with code 255.