3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $name="why";//声明变量$name,并初始化 function echoName1() { //在函数echoName1()里使用global来声明$name global $name; echo "the first name is ".$name."<br>"; } function echoName2() { //在函数echoName2()里没有使用global来声明$name echo "the second name is ".$name."<br>"; } echoName1(); echoName2(); $last_name = "O'Keefe"; echo $sql = "select * from users where last_name = '" . addslashes($last_name) . "'"; class Person { //下面是人的成员属性 var $name; //人的名子 var $sex; //人的性别 var $age; //人的年龄 //定义一个构造方法参数为属性姓名$name、性别$sex和年龄$age进行赋值 function __construct($name = "", $sex = "", $age = "") { $this->name=$name; $this->sex=$sex; $this->age=$age; } //这个人可以说话的方法, 说出自己的属性 function say() { echo "我的名子叫:" . $this->name . " 性别:" . $this->sex . " 我的年龄是:" . $this->age . "<br>"; } //对象克隆时自动调用的方法, 如果想在克隆后改变原对象的内容,需要在__clone()中重写原本的属性和方法 function __clone() { //$this指的复本p2, 而$that是指向原本p1,这样就在本方法里,改变了复本的属性。 $this->name = "我是假的 $that->name"; $this->age = 30; } } $p1 = new Person("张三", "男", 20); $p2 = clone $p1; $p1->say(); $p2->say();
Output for 5.1.3 - 7.1.0
the first name is why<br> Notice: Undefined variable: name in /in/SjORJ on line 16 the second name is <br>select * from users where last_name = 'O\'Keefe' Notice: Undefined variable: that in /in/SjORJ on line 47 Notice: Trying to get property of non-object in /in/SjORJ on line 47 我的名子叫:张三 性别:男 我的年龄是:20<br>我的名子叫:我是假的 性别:男 我的年龄是:30<br>
Output for 5.0.4 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/SjORJ on line 27 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/SjORJ on line 28 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/SjORJ on line 29 the first name is why<br> Notice: Undefined variable: name in /in/SjORJ on line 16 the second name is <br>select * from users where last_name = 'O\'Keefe' Notice: Undefined variable: that in /in/SjORJ on line 47 Notice: Trying to get property of non-object in /in/SjORJ on line 47 我的名子叫:张三 性别:男 我的年龄是:20<br>我的名子叫:我是假的 性别:男 我的年龄是:30<br>
Output for 5.0.0 - 5.0.3
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/SjORJ on line 27 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/SjORJ on line 28 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/SjORJ on line 29 the first name is why<br> Notice: Undefined variable: name in /in/SjORJ on line 16 the second name is <br>select * from users where last_name = 'O\'Keefe' Notice: Undefined variable: that in /in/SjORJ on line 47 Notice: Trying to get property of non-object in /in/SjORJ on line 47 我的名子叫:张三 性别:男 我的年龄是:20<br>我的名子叫:我是假的 性别:男 我的年龄是:30<br>
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_VARIABLE in /in/SjORJ on line 54
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_VARIABLE in /in/SjORJ on line 54
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/SjORJ on line 54
Process exited with code 255.