note 93343 added to function.get-called-class

From: Date: Fri, 04 Sep 2009 11:29:10 +0000
Subject: note 93343 added to function.get-called-class
Groups: php.notes 
Request: Send a blank email to php-notes+get-160212@lists.php.net to get a copy of this message
Previous note had some drawbacks. So here is a better one: <?php if(!function_exists('get_called_class')) { function get_called_class() { $matches=array(); $bt = debug_backtrace(); $l = 0; do { $l++; $lines = file($bt[$l]['file']); $callerLine = $lines[$bt[$l]['line']-1]; if (!preg_match('/([a-zA-Z0-9\_]+)::'.$bt[$l]['function'].'/', $callerLine, $matches)) { preg_match('/([a-zA-Z0-9\_]+)::\$[a-zA-Z0-9\_]+/', $callerLine, $matches); } if (!isset($matches[1])) $matches[1]=NULL; //for notices if ($matches[1] == 'self') { $line = $bt[$l]['line']-1; while ($line > 0 && strpos($lines[$line], 'class') === false) { $line--; } preg_match('/class[\s]+(.+?)[\s]+/si', $lines[$line], $matches); } } while ($matches[1] == 'parent' && $matches[1]); return $matches[1]; } } ?> ---- Server IP: 160.75.100.7 Probable Submitter: 85.105.22.157 ---- Manual Page -- http://www.php.net/manual/en/function.get-called-class.php Edit -- https://master.php.net/note/edit/93343 Del: integrated -- https://master.php.net/note/delete/93343/integrated Del: useless -- https://master.php.net/note/delete/93343/useless Del: bad code -- https://master.php.net/note/delete/93343/bad+code Del: spam -- https://master.php.net/note/delete/93343/spam Del: non-english -- https://master.php.net/note/delete/93343/non-english Del: in docs -- https://master.php.net/note/delete/93343/in+docs Del: other reasons-- https://master.php.net/note/delete/93343 Reject -- https://master.php.net/note/reject/93343 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160212) next »