note 82873 added to function.get-class
| From: | dave dot zap at gmail dot com | Date: | Wed, 30 Apr 2008 04:13:43 +0000 |
| Subject: | note 82873 added to function.get-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-138924@lists.php.net to get a copy of this message | ||
Take care using the backtrace method to find the calling class of a static method, you should step
backward through the array and find a match for your getInstance() function. In backtrace the class
name you want is not always the last item in the array.
I will not post the whole singleton class here, but have made the following modification to Frederik
Krautwald's method (found below)
<?php
$bt = debug_backtrace();
// this method is count($bt)-1) by Frederik will fall over when calling getInstance from within an
include file.
//$class = $bt[count($bt) - 1]['class'];
for( $i=count($bt)-1 ; $i > 0 ; $i--)
{
if($bt[$i]['function'] == 'getInstance')
{
$class = $bt[$i]['class'];
break;
}
}
?>
----
Server IP: 202.89.58.1
Probable Submitter: 203.97.108.111
----
Manual Page -- http://www.php.net/manual/en/function.get-class.php
Edit -- https://master.php.net/note/edit/82873
Del: integrated -- https://master.php.net/note/delete/82873/integrated
Del: useless -- https://master.php.net/note/delete/82873/useless
Del: bad code -- https://master.php.net/note/delete/82873/bad+code
Del: spam -- https://master.php.net/note/delete/82873/spam
Del: non-english -- https://master.php.net/note/delete/82873/non-english
Del: in docs -- https://master.php.net/note/delete/82873/in+docs
Del: other reasons-- https://master.php.net/note/delete/82873
Reject -- https://master.php.net/note/reject/82873
Search -- https://master.php.net/manage/user-notes.php