3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyClass { protected $arr; public function __construct() { $this->arr = array(); } public function getArr() { return $this->arr; } public function append($arr) { $this->$arr[] = $arr; } public function merge($arr) { $this->arr = array_merge($this->arr, $arr); } } $arr = array('a','b'); $obj = new MyClass(); $obj->append($arr);//使用append无法修改类属性 var_dump($obj->getArr()); //output : //array(0){} $obj->merge($arr);//使用merge可以 var_dump($obj->getArr()); //output: //array(2){'a','b'}
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Array to string conversion in /in/2Mq98 on line 15 Deprecated: Creation of dynamic property MyClass::$Array is deprecated in /in/2Mq98 on line 15 array(0) { } array(2) { [0]=> string(1) "a" [1]=> string(1) "b" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.03 ms | 401 KiB | 8 Q