|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-01-12 22:07 UTC] blue-tidus159 at hotmail dot com
Description:
------------
The problem with debug_backtrace() is, that only function parameter values which are native types can be changed, but not if the value is an object.
Test script:
---------------
<?php
function errorHandler($level, $msg){
$debug = debug_backtrace();
$debug[1]['args'][0]='1';
return true;
}
set_error_handler('error');
function a($a){ // E_RECOVERABLE_ERROR
var_dump($a);
}
class A{}
a(1);
a(2);
a(new A());
?>
Expected result:
----------------
int 1
int 1
int 1
Actual result:
--------------
int 1
int 1
object A
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 18 19:00:01 2025 UTC |
Little typo, i meant: set_error_handler('errorHandler');I just realized that a similar effect can be reached by setting the reference mark before the parameter name. The problem is just that the original object will be changed too. function a(&$a){ var_dump($a); } $test = new A(); var_dump($test); // object A a($test) // int 1 var_dump($test); // int 1 => this should still be object A, you should create internally a new reference parameter variable referencing the passed object if you know what i mean. I know that native values get copied and that there is no problem with overwriting the value. But objects could be handled like this: if used as parameter value, create a new reference variable referencing the object, this variable can then be overwritten without changing the original object.