You can trace the deprecated error messages as well with set_error_handler()
. The problem you describe is, that these deprication messages are given before you have registered your error handling function.
The two messages you name are given at parse-time. That means if you register your error handler function too late, you can not handle them any longer (because they have passed).
The solution therefore is trivial: Register your error handler before these files are parsed. Working Example:
File error-handler-deprecated-include.php
:
<?php
# 1. Assigning the return value of new by reference is now deprecated.
$var = &new stdClass();
# 2. Call-time pass-by-reference is now deprecated
trim(&$var);
File error-handler-deprecated.php
:
<?php
$handler = function($errno, $errstr, $errfile, $errline) {
echo "Error: ", var_dump($errno, $errstr, $errfile, $errline),
"-----------------------------------\n";
};
echo 'set_error_handler() [previous handler]: ',
var_dump(set_error_handler($handler));
# test 1. and 2. by including the code *after* the error handler has been set
include('error-handler-deprecated-include.php');
Running php error-handler-deprecated.php
under PHP 5.3 then produces the following output, as you can see the error handler is handling all those deprecated messages next to the other errors:
set_error_handler() [previous handler]: NULL
Error: int(8192)
string(60) "Assigning the return value of new by reference is deprecated"
string(98) "error-handler-deprecated-include.php"
int(7)
-----------------------------------
Error: int(8192)
string(47) "Call-time pass-by-reference has been deprecated"
string(98) "error-handler-deprecated-include.php"
int(10)
-----------------------------------
Error: int(2)
string(53) "trim() expects parameter 1 to be string, object given"
string(98) "error-handler-deprecated-include.php"
int(10)
-----------------------------------