note 90433 added to function.get-called-class
| From: | joel at geekoracle dot com | Date: | Wed, 22 Apr 2009 07:36:30 +0000 |
| Subject: | note 90433 added to function.get-called-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153568@lists.php.net to get a copy of this message | ||
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];
}
}
----
Server IP: 69.147.83.197
Probable Submitter: 99.226.131.208
----
Manual Page -- http://www.php.net/manual/en/function.get-called-class.php
Edit -- https://master.php.net/note/edit/90433
Del: integrated -- https://master.php.net/note/delete/90433/integrated
Del: useless -- https://master.php.net/note/delete/90433/useless
Del: bad code -- https://master.php.net/note/delete/90433/bad+code
Del: spam -- https://master.php.net/note/delete/90433/spam
Del: non-english -- https://master.php.net/note/delete/90433/non-english
Del: in docs -- https://master.php.net/note/delete/90433/in+docs
Del: other reasons-- https://master.php.net/note/delete/90433
Reject -- https://master.php.net/note/reject/90433
Search -- https://master.php.net/manage/user-notes.php