|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-12-23 11:01 UTC] nikic@php.net
-Status: Open
+Status: Wont fix
-Package: Feature/Change Request
+Package: *General Issues
[2017-12-23 11:01 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 29 18:00:01 2025 UTC |
Description: ------------ When setting up a custom error handler to deal with errors triggered from within instantiated objects, it would be extremely useful to have a copy of the object the error was triggered from. For instance, when writing a detailed class that will be extended by several individual classes, it would be very useful to have access to things like get_class($errcontext['this']) or individual members, such as an $id member. Having this available within the context passed to the error handler would help narrow down why the error occured. Currently the only option for this case is to implement a custom error trigger function in the base class, which then calls trigger_error() after prepending the error string with the class name and any useful data. This is an acceptable workaround if there is a particular reason $this is not passed in the error context, but it would be far more convenient in general for these situations, and there are likely other situations I haven't run into yet. Reproduce code: --------------- function error_function($errno, $errstr, $errfile, $errline, $errcontext) { if(isset($errcontext['this'])) { $class = get_class($errcontext['this']); $id = $errcontext['this']->id; if($id) print "Class $class (ID $id): $errstr"; print "Class $class (no ID): $errstr"; } print $errstr; } set_error_handler('error_function'); class test_class { private $id; function __construct($id = NULL) { $this->id = $id; trigger_error('Test error'); } } $test = new test_class(5); Expected result: ---------------- Class test_class (ID 5): Test error Actual result: -------------- Test error