note 92198 deleted from function.get-called-class by danbrown
| From: | danbrown@php.net | Date: | Fri, 08 Jun 2012 20:18:52 +0000 |
| Subject: | note 92198 deleted from function.get-called-class by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188496@lists.php.net to get a copy of this message | ||
Note Submitter: spidgorny at gmail dot com
----
My modification to the get_called_class() simulation function, which takes care of the parent::
calls. It goes further into the backtrace to find the first non "parent" call. This way we
pop-up to the original caller class. I'm not sure if this is the default behavior of the
original PHP 5.3 function.
<?php
// http://us.php.net/manual/en/function.get-called-class.php#89478
if (!function_exists('get_called_class')):
function get_called_class() {
$bt = debug_backtrace();
//debug($bt);
$l = 0;
do {
$l++;
$lines = file($bt[$l]['file']);
$callerLine = $lines[$bt[$l]['line']-1];
//debug($callerLine);
preg_match('/([a-zA-Z0-9\_]+)::'.$bt[$l]['function'].'/',
$callerLine,
$matches);
} while ($matches[1] == 'parent' && $matches[1]);
return $matches[1];
}
endif;
?>