Skip to content

Instantly share code, notes, and snippets.

@ssigwart
Last active January 28, 2021 14:29
Show Gist options
  • Save ssigwart/6716ce348668106e6debad1ff031e9be to your computer and use it in GitHub Desktop.
Save ssigwart/6716ce348668106e6debad1ff031e9be to your computer and use it in GitHub Desktop.
Deceiving PHP Exception Trace
<?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