Search code examples
phpphp-5.4

PHP 5.4 does not recognize parent constant


I migrated my cloud server, and after install all lamp stuff and clone my repository my php just does not recognizes the 'parent' constant.

My log says.

[Wed Jul 08 21:29:28 2015] [error] [client 186.223.169.223] PHP Notice: Use of undefined constant parent - assumed 'parent' in /home/dev/xxx/Funcionario.php on line 11, referer: xxx

And in code I have

class Funcionario extends Model {

    protected function init() {
        $this -> db = DataBase::getInstance('000001');

        call_user_func_array(array( parent, 'init'), func_get_args() );
    }
}

Obs. PHP-5.4

Thanks.


Solution

  • Use of undefined constant parent - assumed 'parent'

    This is because parent not being followed by the scope operator :: is considered a constant; it works fine if you make it a string:

    call_user_func_array(array('parent', 'init'), func_get_args());
    

    It works fine without it as well, the only reason why you're seeing that notice now is because of a different error_reporting level.