note 90433 deleted from function.get-called-class by danbrown
| From: | danbrown@php.net | Date: | Wed, 22 Apr 2009 12:52:07 +0000 |
| Subject: | note 90433 deleted from function.get-called-class by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153582@lists.php.net to get a copy of this message | ||
Note Submitter: joel at geekoracle dot com
----
A modification to progman at centrum dot sk's implementation:
<?php
function get_called_class() {
$bt = debug_backtrace();
//print_r($bt);
$lines = file($bt[1]['file']);
preg_match('/([a-zA-Z0-9\_]+)::'.$bt[1]['function'].'/',
$lines[$bt[1]['line']-1],
$matches);
if ('self' != $matches[1] && '' != $matches[1]) {
return $matches[1];
}
// handles self::someMethod()
if ( isset($bt[2]['class']) && ('::' == $bt[2]['type']) ) {
return $bt[2]['class'];
}
// handles call_user_func() and call_user_func_array()
if ( ('call_user_func' == $bt[2]['function']) ||
('call_user_func_array' == $bt[2]['function']) ) {
return $bt[2]['args'][0][0];
}
}