Maico Borges Maico Borges - 1 year ago 79
PHP Question

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] 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


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download