The ReflectionObject class

(PHP 5)

Introduction

The ReflectionObject class reports information about an object.

Class synopsis

ReflectionObject extends ReflectionClass implements Reflector {
/* Constants */
const integer IS_IMPLICIT_ABSTRACT = 16 ;
const integer IS_EXPLICIT_ABSTRACT = 32 ;
const integer IS_FINAL = 64 ;
/* Properties */
public $name ;
/* Methods */
public __construct ( object $argument )
public static string export ( string $argument [, bool $return ] )
/* Inherited methods */
public ReflectionClass::__construct ( mixed $argument )
public static string ReflectionClass::export ( mixed $argument [, bool $return = false ] )
public mixed ReflectionClass::getConstant ( string $name )
public array ReflectionClass::getConstants ( void )
public ReflectionMethod ReflectionClass::getConstructor ( void )
public string ReflectionClass::getDocComment ( void )
public int ReflectionClass::getEndLine ( void )
public ReflectionExtension ReflectionClass::getExtension ( void )
public string ReflectionClass::getExtensionName ( void )
public string ReflectionClass::getFileName ( void )
public array ReflectionClass::getInterfaceNames ( void )
public array ReflectionClass::getInterfaces ( void )
public ReflectionMethod ReflectionClass::getMethod ( string $name )
public array ReflectionClass::getMethods ([ int $filter ] )
public int ReflectionClass::getModifiers ( void )
public string ReflectionClass::getName ( void )
public string ReflectionClass::getNamespaceName ( void )
public object ReflectionClass::getParentClass ( void )
public array ReflectionClass::getProperties ([ int $filter ] )
public ReflectionProperty ReflectionClass::getProperty ( string $name )
public string ReflectionClass::getShortName ( void )
public int ReflectionClass::getStartLine ( void )
public mixed ReflectionClass::getStaticPropertyValue ( string $name [, mixed &$def_value ] )
public array ReflectionClass::getTraitAliases ( void )
public array ReflectionClass::getTraitNames ( void )
public array ReflectionClass::getTraits ( void )
public bool ReflectionClass::hasConstant ( string $name )
public bool ReflectionClass::hasMethod ( string $name )
public bool ReflectionClass::hasProperty ( string $name )
public bool ReflectionClass::implementsInterface ( string $interface )
public bool ReflectionClass::inNamespace ( void )
public bool ReflectionClass::isAbstract ( void )
public bool ReflectionClass::isCloneable ( void )
public bool ReflectionClass::isFinal ( void )
public bool ReflectionClass::isInstance ( object $object )
public bool ReflectionClass::isInstantiable ( void )
public bool ReflectionClass::isInterface ( void )
public bool ReflectionClass::isInternal ( void )
public bool ReflectionClass::isIterateable ( void )
public bool ReflectionClass::isSubclassOf ( string $class )
public bool ReflectionClass::isTrait ( void )
public bool ReflectionClass::isUserDefined ( void )
public object ReflectionClass::newInstance ( mixed $args [, mixed $... ] )
public object ReflectionClass::newInstanceArgs ([ array $args ] )
public void ReflectionClass::setStaticPropertyValue ( string $name , string $value )
public string ReflectionClass::__toString ( void )
}

Properties

name

Name of the object's class. Read-only, throws ReflectionException in attempt to write.

Table of Contents

Коментарии

To simply enlist all methods and properties of an object simply write:

<?php ReflectionObject::export($yourObject); ?>

,which will cause an var_export-like output.
2009-09-02 05:42:33
http://php5.kiev.ua/manual/ru/class.reflectionobject.html
<?php
   
class FullReflectionObject {

       
/**
        * @var obj => $ReflectionObject = propriedade que representa o objeto $ReflectionObject
        * @var obj => $ReflectionProperty = propriedade que representa o objeto $ReflectionProperty
        * @var obj => $ReflectionMethod = propriedade que representa o objeto $ReflectionMethod
        * @var obj => $ReflectionParameter = propriedade que representa o objeto $ReflectionParameter
        * @var bol => $reflect_object = true se o método object() for invocado
        * @var bol => $reflect_property = true se o método property() for invocado
        * @var bol => $reflect_method = true se o método method() for invocado
        * @var bol => $reflect_parameter = true se o método parameter() for invocado
        */

       
private $ReflectionObject;
        private 
$ReflectionProperty;
        private 
$ReflectionMethod;
        private 
$ReflectionParameter;
        private 
$reflect_object    false;
        private 
$reflect_property  false;
        private 
$reflect_method    false;
        private 
$reflect_parameter false;

       
/**
        * @param obj => $object = objeto a ser refletido
        */
       
public function object(object $object) : object {
           
$this->reflect_object true;
           
$this->ReflectionObject = new \ReflectionObject($object);
            return 
$this;
        }

       
/**
        * @param str => $class_name = nome da classe o qual a properiedade ser refletida pertence
        * @param str => $property = nome da properiedade a ser refletida
        */
       
public function property(string $class_namestring $property) : object {
           
$this->reflect_property true;
           
$this->ReflectionProperty = new \ReflectionProperty($class_name$property);
            return 
$this;
        }

       
/**
        * @param str => $class_name = nome da classe o qual o método ser refletido pertence
        * @param str => $method = nome do método a ser refletido
        */
       
public function method(string $class_namestring $method) : object {
           
$this->reflect_method true;
           
$this->ReflectionMethod = new \ReflectionMethod($class_name$method);
            return 
$this;
        }

       
/**
        * @param str => $class_name = nome da classe o qual o parametro a ser refletido pertence
        * @param str => $method = nome do método o qual o parametro a ser refletido pertence
        * @param str => $parameter = nome do parametro a ser refletido
        */
       
public function parameter(string $class_namestring $methodstring $parameter) : object {
           
$this->reflect_parameter true;
           
$this->ReflectionParameter = new \ReflectionParameter(array($class_name$method), $parameter);
            return 
$this;
        }

        public function 
__call($methodName$args){
            if(
$this->reflect_object){
                return 
call_user_func_array(array($this->ReflectionObject$methodName), $args);
            }
            if(
$this->reflect_property){
                return 
call_user_func_array(array($this->ReflectionProperty$methodName), $args);
            }
            if(
$this->reflect_method){
                return 
call_user_func_array(array($this->ReflectionMethod$methodName), $args);
            }
            if(
$this->reflect_parameter){
                return 
call_user_func_array(array($this->ReflectionParameter$methodName), $args);
            }
        }
    }

   
// Digamos que você tenha no seu projeto a classe Client do pacote Guzzle
   
$FullReflectionObject = new FullReflectionObject;
   
var_dump($FullReflectionObject->object(new GuzzleHttp\Client)->getMethods());
   
var_dump($FullReflectionObject->property('GuzzleHttp\Client''config')->isPrivate());
   
var_dump($FullReflectionObject->method('GuzzleHttp\Client''buildUri')->isPrivate());
   
var_dump($FullReflectionObject->parameter('GuzzleHttp\Client''send''options')->getDefaultValue());
2019-05-21 06:39:33
http://php5.kiev.ua/manual/ru/class.reflectionobject.html

    Поддержать сайт на родительском проекте КГБ