note 41084 deleted from function.set-error-handler by cece
| From: | cece@php.net | Date: | Mon, 29 Mar 2004 21:23:57 +0000 |
| Subject: | note 41084 deleted from function.set-error-handler by cece | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67343@lists.php.net to get a copy of this message | ||
Note Submitter:
----
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>!!'
?>