3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 5.3.0 - 5.3.24, 5.3.26 - 5.4.16
Parse error: syntax error, unexpected '{', expecting '(' in /in/2CHm8 on line 7
Process exited with code 255.
Output for 5.3.25
Parse error: syntax error, unexpected '{', expecting '(' in /in/utf6m on line 7
Process exited with code 255.