note 85802 added to language.oop5.late-static-bindings

From: Date: Thu, 18 Sep 2008 14:51:29 +0000
Subject: note 85802 added to language.oop5.late-static-bindings
Groups: php.notes 
Request: Send a blank email to php-notes+get-144511@lists.php.net to get a copy of this message
get_called_class for PHP < 5.3 /** * Return called class name * * @author Michael Grenier * @param int $i_level optional * @return string */ function get_called_class ($i_level = 1) { $a_debug = debug_backtrace(); $a_called = array(); $a_called_function = $a_debug[$i_level]['function']; for ($i = 1, $n = sizeof($a_debug); $i < $n; $i++) { if (in_array($a_debug[$i]['function'], array('eval')) || strpos($a_debug[$i]['function'], 'eval()') !== false) continue; if (in_array($a_debug[$i]['function'], array('__call', '__callStatic'))) $a_called_function = $a_debug[$i]['args'][0]; if ($a_debug[$i]['function'] == $a_called_function) $a_called = $a_debug[$i]; } if (isset($a_called['object']) && isset($a_called['class'])) return (string)$a_called['class']; $i_line = (int)$a_called['line'] - 1; $a_lines = explode("\n", file_get_contents($a_called['file'])); preg_match("#([a-zA-Z0-9_]+){$a_called['type']} {$a_called['function']}( )*\(#", $a_lines[$i_line], $a_match); unset($a_debug, $a_called, $a_called_function, $i_line, $a_lines); if (sizeof($a_match) > 0) $s_class = (string)trim($a_match[1]); else $s_class = (string)$a_called['class']; if ($s_class == 'self') return get_called_class($i_level + 2); return $s_class; } ---- Server IP: 66.207.199.35 Probable Submitter: 24.212.71.52 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.late-static-bindings.php Edit -- https://master.php.net/note/edit/85802 Del: integrated -- https://master.php.net/note/delete/85802/integrated Del: useless -- https://master.php.net/note/delete/85802/useless Del: bad code -- https://master.php.net/note/delete/85802/bad+code Del: spam -- https://master.php.net/note/delete/85802/spam Del: non-english -- https://master.php.net/note/delete/85802/non-english Del: in docs -- https://master.php.net/note/delete/85802/in+docs Del: other reasons-- https://master.php.net/note/delete/85802 Reject -- https://master.php.net/note/reject/85802 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144511) next »