note 41085 added to function.set-error-handler

From: Date: Mon, 29 Mar 2004 21:13:33 +0000
Subject: note 41085 added to function.set-error-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-67342@lists.php.net to get a copy of this message
[delete my previous post plz, update:] 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 work $eh->setIni(); // call this method when you're ready with configuring the class. All other methods that will be called will have no effect on the errorHandling by PHP 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+41085 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41085&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41085&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67342) next »