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);

preferences:
33.51 ms | 402 KiB | 5 Q