var_dump()现在获取类函数名称吗?

时间:2011-07-10 04:12:59

标签: php

class animal
{
  var $type;
  var $says;

  function __construct($_type)
  {
      $type = $_type;
  }

  function Does_he_think_hes_the_boss()
  {
      return ($type == 'cat');
  }  
} // animal

$dog = new animal('dog');

var_dump($dog);

给出

object(animal)[1]
  public 'type' => null
  public 'says' => null

我希望得到尽可能多的关于类的信息(用于调试porpoises) - 变量的名称,函数的名称(如果可能的话,带有它们的签名),父类(如果有的话)等等......

我可以从一个物体获得多少信息?

2 个答案:

答案 0 :(得分:3)

您可以使用reflection

检索有关对象的所有详细信息

答案 1 :(得分:0)

您可以查看debug_backtrace()

function dump( $var ) {
    $result = var_export( $var, true );
    $loc = whereCalled();
    return "\n<pre>Dump: $loc\n$result</pre>";
}

function whereCalled( $level = 1 ) {
    $trace = debug_backtrace();
    $file   = $trace[$level]['file'];
    $line   = $trace[$level]['line'];
    $object = $trace[$level]['object'];
    if (is_object($object)) { $object = get_class($object); }

    return "Where called: line $line of $object \n(in $file)";
}