note 41085 modified in function.set-error-handler by cece
| From: | cece@php.net | Date: | Mon, 29 Mar 2004 21:24:28 +0000 |
| Subject: | note 41085 modified in function.set-error-handler by cece | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67344@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 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>!!'
?>
--was--
[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>!!'
?>
http://www.php.net/manual/en/function.set-error-handler.php