note 41084 added to function.set-error-handler

From: Date: Mon, 29 Mar 2004 21:03:39 +0000
Subject: note 41084 added to function.set-error-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-67341@lists.php.net to get a copy of this message
It seems that when you're letting PHP know that you have a custom error handler, you're not able to -update/set new- variables inside the class. Example: <?php class error { var $error; function error() { $this->setIni(); // this causes PHP to ignore all other changes to the class. } function handler() { echo $this->error.'!!'; } function setText($text) { $this->error = $text; } function setIni() { set_error_handler(array($this, 'handler')); } } $eh = new error; $eh->setText('Error! <br>'); // this will not be saved trigger_error('text', E_USER_ERROR); // prints '!!' ?> How it should be done: <?php class error { var $error; function error() { // dont let PHP know of our error handler yet } function handler() { echo $this->error.'!!'; } function setText($text) { $this->error = $text; } function setIni() { set_error_handler(array($this, 'handler')); } } $eh = new error; $eh->setText('Error! <br>'); // this will not work $eh->setIni(); // do this when you don't want to set variables of the class trigger_error('text', E_USER_ERROR); // prints 'Error! <br>!!' ?> ---- Manual Page -- http://www.php.net/manual/en/function.set-error-handler.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41084 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41084&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41084&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67341) next »