首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP中导出反射类的格式?

PHP中导出反射类的格式?
EN

Stack Overflow用户
提问于 2011-06-08 12:22:30
回答 1查看 1.2K关注 0票数 15

PHP反射层次结构中的每个对象都有一个静态导出方法。您可以使用它来获取类的字符串表示。编写类似下面这样的代码

代码语言:javascript
复制
$c = new ReflectionClass('Mage_Core_Model_Abstract');
ReflectionClass::export($c)

将回显以下内容

代码语言:javascript
复制
Class [ <internal:Reflection> class ReflectionClass implements Reflector ] {

  - Constants [3] {
    Constant [ integer IS_IMPLICIT_ABSTRACT ] { 16 }
    Constant [ integer IS_EXPLICIT_ABSTRACT ] { 32 }
    Constant [ integer IS_FINAL ] { 64 }
  }

  - Static properties [0] {
  }

  - Static methods [1] {
    Method [ <internal:Reflection> static public method export ] {

      - Parameters [2] {
        Parameter #0 [ <required> $argument ]
        Parameter #1 [ <optional> $return ]
      }
    }
  }

  - Properties [1] {
    Property [ <default> public $name ]
  }

  - Methods [43] {
    Method [ <internal:Reflection> final private method __clone ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection, ctor> public method __construct ] {

      - Parameters [1] {
        Parameter #0 [ <required> $argument ]
      }
    }

    Method [ <internal:Reflection> public method __toString ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getName ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method isInternal ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method isUserDefined ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method isInstantiable ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getFileName ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getStartLine ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getEndLine ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getDocComment ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getConstructor ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method hasMethod ] {

      - Parameters [1] {
        Parameter #0 [ <required> $name ]
      }
    }

    Method [ <internal:Reflection> public method getMethod ] {

      - Parameters [1] {
        Parameter #0 [ <required> $name ]
      }
    }

    Method [ <internal:Reflection> public method getMethods ] {

      - Parameters [1] {
        Parameter #0 [ <optional> $filter ]
      }
    }

    Method [ <internal:Reflection> public method hasProperty ] {

      - Parameters [1] {
        Parameter #0 [ <required> $name ]
      }
    }

    Method [ <internal:Reflection> public method getProperty ] {

      - Parameters [1] {
        Parameter #0 [ <required> $name ]
      }
    }

    Method [ <internal:Reflection> public method getProperties ] {

      - Parameters [1] {
        Parameter #0 [ <optional> $filter ]
      }
    }

    Method [ <internal:Reflection> public method hasConstant ] {

      - Parameters [1] {
        Parameter #0 [ <required> $name ]
      }
    }

    Method [ <internal:Reflection> public method getConstants ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getConstant ] {

      - Parameters [1] {
        Parameter #0 [ <required> $name ]
      }
    }

    Method [ <internal:Reflection> public method getInterfaces ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getInterfaceNames ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method isInterface ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method isAbstract ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method isFinal ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getModifiers ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method isInstance ] {

      - Parameters [1] {
        Parameter #0 [ <required> $object ]
      }
    }

    Method [ <internal:Reflection> public method newInstance ] {

      - Parameters [1] {
        Parameter #0 [ <required> $args ]
      }
    }

    Method [ <internal:Reflection> public method newInstanceArgs ] {

      - Parameters [1] {
        Parameter #0 [ <optional> array $args ]
      }
    }

    Method [ <internal:Reflection> public method getParentClass ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method isSubclassOf ] {

      - Parameters [1] {
        Parameter #0 [ <required> $class ]
      }
    }

    Method [ <internal:Reflection> public method getStaticProperties ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getStaticPropertyValue ] {

      - Parameters [2] {
        Parameter #0 [ <required> $name ]
        Parameter #1 [ <optional> $default ]
      }
    }

    Method [ <internal:Reflection> public method setStaticPropertyValue ] {

      - Parameters [2] {
        Parameter #0 [ <required> $name ]
        Parameter #1 [ <required> $value ]
      }
    }

    Method [ <internal:Reflection> public method getDefaultProperties ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method isIterateable ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method implementsInterface ] {

      - Parameters [1] {
        Parameter #0 [ <required> $interface ]
      }
    }

    Method [ <internal:Reflection> public method getExtension ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getExtensionName ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method inNamespace ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getNamespaceName ] {

      - Parameters [0] {
      }
    }

    Method [ <internal:Reflection> public method getShortName ] {

      - Parameters [0] {
      }
    }
  }
}

这种格式是什么?如果这仅仅是内部PHP团队开发的任意格式,或者这是一种已知的格式,可以由其他著名的编程工具解析?

为了澄清,我知道什么是反射以及如何使用它。我好奇的是这种“导出”格式,它看起来是故意设计的,但却不是有效的PHP。它是某种标准的CS/编程格式,还是PHP的一次性格式?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-09 10:19:50

这种格式是Zend引擎如何存储类的一种表示。一旦Zend引擎解析了它,那么它就不是有效的PHP。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6274195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档