當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。