3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CParent { private $arrMember = array(); private $mark; function __construct() { $this->setAttr(); } protected abstract function init(); 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.25 - 5.3.26, 5.4.16
Fatal error: Class CParent contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (CParent::init) in /in/GWqk5 on line 25
Process exited with code 255.
Output for 5.3.0 - 5.3.24, 5.4.0 - 5.4.15
Fatal error: Class CParent contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (CParent::init) in I1AYl on line 25
Process exited with code 255.

preferences:
183.81 ms | 1395 KiB | 51 Q