3v4l.org

run code in 300+ PHP versions simultaneously
<?php class main{ private $name = "李三"; private function __set($_name,$_val){ $this->$_name=$_val;//当外面直接设置私有成员属性$name的时候被自动调用 } private function __get($_name){ retrun $this->$_name;//当外面直接使用私有成员属性$name的时候被自动调用 } } $my = new main; $my->name="李四";//此时,就调用了__set()魔术方法 echo $my->name;//此时,就调用__get()魔术方法
Output for 5.4.0 - 5.4.34
Warning: The magic method __set() must have public visibility and cannot be static in /in/gsGmD on line 4 Warning: The magic method __get() must have public visibility and cannot be static in /in/gsGmD on line 7 Parse error: syntax error, unexpected '$this' (T_VARIABLE) in /in/gsGmD on line 8
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Warning: The magic method __set() must have public visibility and cannot be static in /in/gsGmD on line 4 Warning: The magic method __get() must have public visibility and cannot be static in /in/gsGmD on line 7 Parse error: syntax error, unexpected T_VARIABLE in /in/gsGmD on line 8
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_VARIABLE in /in/gsGmD on line 8
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_VARIABLE in /in/gsGmD on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/gsGmD on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/gsGmD on line 3
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/gsGmD on line 3
Process exited with code 255.

preferences:
179.31 ms | 1016 KiB | 7 Q