当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionClass::GetProperties方法代码示例

本文整理汇总了PHP中ReflectionClass::GetProperties方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::GetProperties方法的具体用法?PHP ReflectionClass::GetProperties怎么用?PHP ReflectionClass::GetProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionClass的用法示例。


在下文中一共展示了ReflectionClass::GetProperties方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: LinkObject

 public function LinkObject($Object, $ConstsWithPrefix = true, $MethodsWithPrefix = false, $PropertiesWithPrefix = false)
 {
     # Reflection
     $Class = new ReflectionClass($Object);
     $ClassName = $Class->GetShortName();
     $Constants = $Class->GetConstants();
     $Methods = $Class->GetMethods(ReflectionMethod::IS_PUBLIC);
     $Properties = $Class->GetProperties(ReflectionProperty::IS_PUBLIC);
     # Prefixes
     $ClassPrefix = $ClassName . '_';
     $ConstsPrefix = $ConstsWithPrefix ? strtoupper($ClassPrefix) : null;
     $MethodsPrefix = $MethodsWithPrefix ? $ClassPrefix : null;
     $PropertiesPrefix = $PropertiesWithPrefix ? $ClassPrefix : null;
     # Consts
     $this->AssignVariables($Constants, $ConstsPrefix);
     # Callbacks
     /**
      * If you can do this
      * In one line
      * Without using aux vars
      * Without repeating code
      * Without doing things like: asd($a = dsa(), ...)
      * 
      * YOU'RE A GOD. 
      */
     // Convert ReflectionMethod's into array(MethodName => Callback, [...])
     $Methods = array_map(function ($Method) {
         return $Method->name;
     }, $Methods);
     $Methods = array_combine($Methods, array_map(function ($Method) use($Object) {
         return array($Object, $Method);
     }, $Methods));
     $Methods = array_filter($Methods, function ($Method) {
         return strpos($Method, '__') !== 0;
     }, ARRAY_FILTER_USE_KEY);
     $this->RegisterCallbacks($Methods, $MethodsPrefix);
     # Vars
     // Convert ReflectionProperty's into array(PropertyName => Value, [...])
     $Properties = array_map(function ($Property) {
         return $Property->name;
     }, $Properties);
     $Properties = array_combine($Properties, array_map(function ($Property) use($Object) {
         return $Object->{$Property};
     }, $Properties));
     $this->AssignVariables($Properties);
     return true;
     // Return consts && methods && properties (all of it)
 }
开发者ID:hasanalom,项目名称:WhatsBot,代码行数:48,代码来源:LuaWithPHP.php

示例2: ReflectionClass

<?php

class ancester
{
    public $ancester = 0;
    function __construct()
    {
        return $this->ancester;
    }
}
class foo extends ancester
{
    public $bar = "1";
    function __construct()
    {
        return $this->bar;
    }
}
$r = new ReflectionClass('foo');
foreach ($r->GetProperties() as $p) {
    echo $p->getName() . " " . $p->getDeclaringClass()->getName() . "\n";
}
开发者ID:gleamingthecube,项目名称:php,代码行数:22,代码来源:ext_reflection_tests_bug36434.php


注:本文中的ReflectionClass::GetProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。