栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

找出哪个类别在另一个类别中称为方法

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

找出哪个类别在另一个类别中称为方法

您可以这样使用

debug_backtrace

顺便说一句,看看手册页上的评论:有一些有用的功能和建议;-)

class Foo{  public function __construct()  {    $bar = new Bar();    $bar->test();  }}class Bar{  public function test()  {      $trace = debug_backtrace();      if (isset($trace[1])) {          // $trace[0] is ourself          // $trace[1] is our caller          // and so on...          var_dump($trace[1]);          echo "called by {$trace[1]['class']} :: {$trace[1]['function']}";      }  }}$foo = new Foo();

var_dump
会输出:

array  'file' => string '/home/squale/developpement/tests/temp/temp.php' (length=46)  'line' => int 29  'function' => string '__construct' (length=11)  'class' => string 'Foo' (length=3)  'object' =>     object(Foo)[1]  'type' => string '->' (length=2)  'args' =>     array      empty

echo

called by Foo :: __construct

但是,尽管看起来不错,但我不确定它是否应该在您的应用程序中用作“正常事物” …似乎有些奇怪,实际上:设计良好的方法不需要知道它叫什么, 在我看来。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/405462.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号