note 92572 added to function.get-called-class
| From: | steve at visual77 dot com | Date: | Wed, 29 Jul 2009 23:21:53 +0000 |
| Subject: | note 92572 added to function.get-called-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158894@lists.php.net to get a copy of this message | ||
I've furthered enhanced the attempts to fix get_called_class() for PHP 5.2 Using a class and
some static properties, we can keep track of how many times it has already processed the current
line, so multiple calls on the same line will still function properly.
<?php
if(!function_exists('get_called_class')) {
class class_tools {
static $i = 0;
static $fl = null;
static function get_called() {
$bt = debug_backtrace();
if(self::$fl == $bt[2]['file'].$bt[2]['line']) {
self::$i++;
} else {
self::$i = 0;
self::$fl = $bt[2]['file'].$bt[2]['line'];
}
$lines = file($bt[2]['file']);
preg_match_all('/([a-zA-Z0-9\_]+)::'.$bt[2]['function'].'/',
$lines[$bt[2]['line']-1],
$matches);
return $matches[1][self::$i];
}
}
function get_called_class() {
return class_tools::get_called_class();
}
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 24.234.114.199
----
Manual Page -- http://www.php.net/manual/en/function.get-called-class.php
Edit -- https://master.php.net/note/edit/92572
Del: integrated -- https://master.php.net/note/delete/92572/integrated
Del: useless -- https://master.php.net/note/delete/92572/useless
Del: bad code -- https://master.php.net/note/delete/92572/bad+code
Del: spam -- https://master.php.net/note/delete/92572/spam
Del: non-english -- https://master.php.net/note/delete/92572/non-english
Del: in docs -- https://master.php.net/note/delete/92572/in+docs
Del: other reasons-- https://master.php.net/note/delete/92572
Reject -- https://master.php.net/note/reject/92572
Search -- https://master.php.net/manage/user-notes.php