note 92198 added to function.get-called-class

From: Date: Tue, 14 Jul 2009 09:32:39 +0000
Subject: note 92198 added to function.get-called-class
Groups: php.notes 
Request: Send a blank email to php-notes+get-158259@lists.php.net to get a copy of this message
My modification to the get_called_class() simulation function, which takes care of the parent:: calls. It goes further into the backtrace to find the first non "parent" call. This way we pop-up to the original caller class. I'm not sure if this is the default behavior of the original PHP 5.3 function. <?php // http://us.php.net/manual/en/function.get-called-class.php#89478 if (!function_exists('get_called_class')): function get_called_class() { $bt = debug_backtrace(); //debug($bt); $l = 0; do { $l++; $lines = file($bt[$l]['file']); $callerLine = $lines[$bt[$l]['line']-1]; //debug($callerLine); preg_match('/([a-zA-Z0-9\_]+)::'.$bt[$l]['function'].'/', $callerLine, $matches); } while ($matches[1] == 'parent' && $matches[1]); return $matches[1]; } endif; ?> ---- Server IP: 208.69.120.35 Probable Submitter: 84.233.202.2 ---- Manual Page -- http://www.php.net/manual/en/function.get-called-class.php Edit -- https://master.php.net/note/edit/92198 Del: integrated -- https://master.php.net/note/delete/92198/integrated Del: useless -- https://master.php.net/note/delete/92198/useless Del: bad code -- https://master.php.net/note/delete/92198/bad+code Del: spam -- https://master.php.net/note/delete/92198/spam Del: non-english -- https://master.php.net/note/delete/92198/non-english Del: in docs -- https://master.php.net/note/delete/92198/in+docs Del: other reasons-- https://master.php.net/note/delete/92198 Reject -- https://master.php.net/note/reject/92198 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158259) next »