3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CParent { protected $arrMember = array(); protected $mark; function CParent(){ /* * If parent constructor run first, init() method'll get blank array. */ $this->setAttr(); } protected function init(){ return array(); } protected 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') ); } } $c = new CChild(); print_r($c);
Output for git.master, git.master_jit, rfc.property-hooks
CChild Object ( [arrMember:protected] => Array ( ) [mark:protected] => )

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