コード例 #1
0
 static function get_called_class()
 {
     $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];
 }
コード例 #2
0
 static function get_called_class()
 {
     $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);
     if (self::$i >= count($matches[1])) {
         self::$i = count($matches[1]) - 1;
     }
     // temporary workaround by Duke (not thoroughly tested)
     return $matches[1][self::$i];
 }
コード例 #3
0
ファイル: fn.php プロジェクト: ahmatjan/EasyManage
 public static function get_called_class()
 {
     $bt = debug_backtrace();
     //使用call_user_func或call_user_func_array函数调用类方法,处理如下
     if (array_key_exists(3, $bt) && array_key_exists('function', $bt[3]) && in_array($bt[3]['function'], array('call_user_func', 'call_user_func_array'))) {
         //如果参数是数组
         if (is_array($bt[3]['args'][0])) {
             $toret = $bt[3]['args'][0][0];
             return $toret;
         } else {
             if (is_string($bt[3]['args'][0])) {
                 //如果参数是字符串
                 //如果是字符串且字符串中包含::符号,则认为是正确的参数类型,计算并返回类名
                 if (false !== strpos($bt[3]['args'][0], '::')) {
                     $toret = explode('::', $bt[3]['args'][0]);
                     return $toret[0];
                 }
             }
         }
     }
     //BUG修正,复杂环境直接多一层判断
     if (array_key_exists("object", $bt[2]) && array_key_exists("class", $bt[2])) {
         if ($bt[2]['object'] instanceof $bt[2]['class']) {
             return get_class($bt[2]['object']);
         }
     }
     //使用正常途径调用类方法,如:A::make()
     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];
 }