3v4l.org

run code in 300+ PHP versions simultaneously
<?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>"; } } $p1 = new Person("张三", "男", 20); $p1_string = serialize($p1); //把一个对象串行化,返一个字符串 echo $p1_string . "<br>"; //串行化的字符串我们通常不去解析 $p2 = unserialize($p1_string); //把一个串行化的字符串反串行化形成对象$p2 $p2->say();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
the first name is why<br> Warning: Undefined variable $name in /in/dW3cI on line 16 the second name is <br>select * from users where last_name = 'O\'Keefe'O:6:"Person":3:{s:4:"name";s:6:"张三";s:3:"sex";s:3:"男";s:3:"age";i:20;}<br>我的名子叫:张三 性别:男 我的年龄是:20<br>
Output for 5.1.3 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
the first name is why<br> Notice: Undefined variable: name in /in/dW3cI on line 16 the second name is <br>select * from users where last_name = 'O\'Keefe'O:6:"Person":3:{s:4:"name";s:6:"张三";s:3:"sex";s:3:"男";s:3:"age";i:20;}<br>我的名子叫:张三 性别:男 我的年龄是:20<br>
Output for 7.3.32 - 7.3.33
the first name is why<br>the second name is <br>select * from users where last_name = 'O\'Keefe'O:6:"Person":3:{s:4:"name";s:6:"张三";s:3:"sex";s:3:"男";s:3:"age";i:20;}<br>我的名子叫:张三 性别:男 我的年龄是:20<br>
Output for 5.0.4 - 5.0.5, 5.1.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/dW3cI on line 27 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/dW3cI on line 28 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/dW3cI on line 29 the first name is why<br> Notice: Undefined variable: name in /in/dW3cI on line 16 the second name is <br>select * from users where last_name = 'O\'Keefe'O:6:"Person":3:{s:4:"name";s:6:"张三";s:3:"sex";s:3:"男";s:3:"age";i:20;}<br>我的名子叫:张三 性别:男 我的年龄是:20<br>
Output for 5.0.0 - 5.0.3
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/dW3cI on line 27 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/dW3cI on line 28 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/dW3cI on line 29 the first name is why<br> Notice: Undefined variable: name in /in/dW3cI on line 16 the second name is <br>select * from users where last_name = 'O\'Keefe'O:6:"Person":3:{s:4:"name";s:6:"张三";s:3:"sex";s:3:"男";s:3:"age";i:20;}<br>我的名子叫:张三 性别:男 我的年龄是:20<br>
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9
the first name is why<br> Notice: Undefined variable: name in /in/dW3cI on line 16 the second name is <br>select * from users where last_name = 'O\'Keefe'O:6:"person":3:{s:4:"name";N;s:3:"sex";N;s:3:"age";N;}<br>我的名子叫: 性别: 我的年龄是:<br>

preferences:
239.5 ms | 402 KiB | 358 Q