Last active
January 28, 2021 14:29
-
-
Save ssigwart/6716ce348668106e6debad1ff031e9be to your computer and use it in GitHub Desktop.
Deceiving PHP Exception Trace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function traceTest(SplFixedArray $arr, string $str, int $num) | |
{ | |
print '----- Before variables changed -----' . PHP_EOL; | |
$e = new RuntimeException(); | |
print $e->getTraceAsString() . PHP_EOL; | |
debug_print_backtrace(); | |
print PHP_EOL; | |
// Update variables | |
$arr = null; | |
$str = 'new'; | |
$num = 2; | |
print '----- After variables changed -----' . PHP_EOL; | |
$e = new RuntimeException(); | |
print $e->getTraceAsString() . PHP_EOL; | |
debug_print_backtrace(); | |
} | |
traceTest(new SplFixedArray(1), 'original', 1); | |
// Output | |
/* | |
----- Before variables changed ----- | |
#0 /path/to/file.php(43): traceTest(Object(SplFixedArray), 'original', 1) | |
#1 {main} | |
#0 traceTest(SplFixedArray Object ([0] => ), original, 1) called at [/path/to/file.php:43] | |
----- After variables changed ----- | |
#0 /path/to/file.php(43): traceTest(NULL, 'new', 2) | |
#1 {main} | |
#0 traceTest(, new, 2) called at [/path/to/file.php:43] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment