Wait a second - now we get into some serious hacking
The message you send with trigger_error() must be a string. But if you wanted to send an array (or even an object) you can use serialize()
From the manual;
To make the serialized string into a PHP value again, use unserialize(). serialize() handles all types, except the resource-type. You can even serialize() arrays that contain references to itself. References inside the array/object you are serialize()ing will also be stored.
Note: In PHP 3, object properties will be serialized, but methods are lost. PHP 4 removes that limitation and restores both properties and methods. Please see the Serializing Objects section of Classes and Objects for more information.
So for a simple example using an array;
<?php
// Some demo class
class MyEvent {
function MyEvent () {
echo ('Hello World!');
}
}
// Override the E_USER_NOTICE constant with our own name
define ("EVENT",E_USER_NOTICE);
// Set what errors we will respond to, including EVENT
// Note that this overrides PHP ini
error_reporting (E_ERROR | E_WARNING | E_PARSE | EVENT);
// Define the error handling function
function myErrorHandler ($errno, $errstr, $errfile, $errline) {
switch ($errno) {
case EVENT:
// $event=& new $errstr;
// Convert the string back to it's original form
$errstr=unserialize($errstr);
echo ( "<pre>" );
print_r ($errstr);
echo ( "</pre>" );
break;
default:
die ("Application Error:[$errno] $errstr<br />\
");
break;
}
}
// Tell PHP to use the error handler, overriding the in
// built handler - all errors go by our function
$eHandler=set_error_handler('myErrorHandler');
$array=array("one","two");
// turn the array into a serialized string
$array=serialize ($array);
// Trigger an event
trigger_error ($array, EVENT);
?>
It getās interestingā¦
Looks like the error handler itself must be a function - had a quick go at defining a class, even using āmyErrorHandler::myErrorHandlerā without success.