3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CParent { private $arrMember = array(); private $mark; function __construct(){ /* * If parent constructor run first, init() method'll get blank array. */ $this->setAttr(); } protected function init(){ return array(); } private function setAttr(){ $arr = $this->init(); foreach ($arr as $item){ array_push($this->arrMember, $item['name']); if (isset($item['mark']) && $item['mark'] == TRUE) $this->mark = $item['name']; } } } class CChild extends CParent { /* * I'd like to define variable within this method then pass to parent class. */ protected function init(){ return array( array('name' => 'v1', 'mark' => true), array('name' => 'v2'), array('name' => 'v3') ); } } print_r( new CChild);
Output for git.master, git.master_jit, rfc.property-hooks
CChild Object ( [arrMember:CParent:private] => Array ( [0] => v1 [1] => v2 [2] => v3 ) [mark:CParent:private] => v1 )

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:
45.66 ms | 401 KiB | 8 Q