note 108967 added to function.get-called-class
| From: | dsaa at dubli dot com | Date: | Fri, 08 Jun 2012 16:23:09 +0000 |
| Subject: | note 108967 added to function.get-called-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188467@lists.php.net to get a copy of this message | ||
This is the last version of the version < 5.3 workaround
<?php
/**
* Gets the name of the class that made a static call
* (Mimicks the get_called_class function in PHP 5.3)
* @param string $functionName
* @return string
*/
function callerName($functionName=null)
{
$btArray = debug_backtrace();
$btIndex = count($btArray) - 1;
while($btIndex > -1)
{
if(!isset($btArray[$btIndex]['file']))
{
$btIndex--;
if(isset($matches[1]))
{
if(class_exists($matches[1]))
{
return $matches[1];
}
else
{
continue;
}
}
else
{
continue;
}
}
else
{
$lines = file($btArray[$btIndex]['file']);
$callerLine = $lines[$btArray[$btIndex]['line']-1];
if(!isset($functionName))
{
preg_match('/([a-zA-Z\_]+)::/',
$callerLine,
$matches);
}
else
{
preg_match('/([a-zA-Z\_]+)::'.$functionName.'/',
$callerLine,
$matches);
}
$btIndex--;
if(isset($matches[1]))
{
if(class_exists($matches[1]))
{
return $matches[1];
}
else
{
continue;
}
}
else
{
continue;
}
}
}
return $matches[1];
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 66.55.175.74
----
Manual Page -- http://www.php.net/manual/en/function.get-called-class.php
Edit -- https://master.php.net/note/edit/108967
Del: integrated -- https://master.php.net/note/delete/108967/integrated
Del: useless -- https://master.php.net/note/delete/108967/useless
Del: bad code -- https://master.php.net/note/delete/108967/bad+code
Del: spam -- https://master.php.net/note/delete/108967/spam
Del: non-english -- https://master.php.net/note/delete/108967/non-english
Del: in docs -- https://master.php.net/note/delete/108967/in+docs
Del: other reasons-- https://master.php.net/note/delete/108967
Reject -- https://master.php.net/note/reject/108967
Search -- https://master.php.net/manage/user-notes.php