Skip to content

Instantly share code, notes, and snippets.

@ahsankhatri
Last active October 1, 2016 09:11
Show Gist options
  • Save ahsankhatri/2f0d6ed9048c9f1e27df430897241eab to your computer and use it in GitHub Desktop.
Save ahsankhatri/2f0d6ed9048c9f1e27df430897241eab to your computer and use it in GitHub Desktop.
Analyze called function with non-standard php feature to enhance functionality on expected result by caller-identifier
<?php
echo ''; /* sdfds */ echo ''; ;; ! phpMagic(); // echo $i; ?> <?php
;;; +phpMagic(); // $increment with 1;
@phpMagic(); // $increment with 1;
/* $decrement with 1 ;;; */-phpMagic();// $decrement with 1;
/* comment ;;; */ \phpMagic(); /* another comment ;;; */ \phpMagic(); // $decrement with 1;
function phpMagic() {
$poped = array_pop(debug_backtrace());
$fullLine = file($poped['file'])[$poped['line']-1];
foreach (explode(';', $fullLine) as $statements) {
if (preg_match('%(.\s*'.$poped['function'].')\s*\(%', $statements, $match) ) {
$statement = trim($match[1]);
}
}
// called with substr( $statement, 0, 1 ); ! @ + - \
echo $statement . '<br />';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment