downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

ReflectionClass::__construct> <Reflection::getModifierNames
[edit] Last updated: Fri, 26 Apr 2013

view this page in

The ReflectionClass class

(PHP 5)

Introduction

The ReflectionClass class reports information about a class.

Class synopsis

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 */
__construct ( mixed $argument )
public static string export ( mixed $argument [, bool $return = false ] )
public mixed getConstant ( string $name )
public array getConstants ( void )
public ReflectionMethod getConstructor ( void )
public array getDefaultProperties ( void )
public string getDocComment ( void )
public int getEndLine ( void )
public ReflectionExtension getExtension ( void )
public string getExtensionName ( void )
public string getFileName ( void )
public array getInterfaceNames ( void )
public array getInterfaces ( void )
public ReflectionMethod getMethod ( string $name )
public array getMethods ([ string $filter ] )
public int getModifiers ( void )
public string getName ( void )
public string getNamespaceName ( void )
public object getParentClass ( void )
public array getProperties ([ int $filter ] )
public ReflectionProperty getProperty ( string $name )
public string getShortName ( void )
public int getStartLine ( void )
public array getStaticProperties ( void )
public mixed getStaticPropertyValue ( string $name )
public array getTraitAliases ( void )
public array getTraitNames ( void )
public array getTraits ( void )
public bool hasConstant ( string $name )
public bool hasMethod ( string $name )
public bool hasProperty ( string $name )
public bool implementsInterface ( string $interface )
public bool inNamespace ( void )
public bool isAbstract ( void )
public bool isCloneable ( void )
public bool isFinal ( void )
public bool isInstance ( object $object )
public bool isInstantiable ( void )
public bool isInterface ( void )
public bool isInternal ( void )
public bool isIterateable ( void )
public bool isSubclassOf ( string $class )
public bool isTrait ( void )
public bool isUserDefined ( void )
public object newInstance ( mixed $args [, mixed $... ] )
public object newInstanceArgs ([ array $args ] )
public object newInstanceWithoutConstructor ( void )
public void setStaticPropertyValue ( string $name , string $value )
public string __toString ( void )
}

Properties

name

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

Predefined Constants

ReflectionClass Modifiers

ReflectionClass::IS_IMPLICIT_ABSTRACT

Indicates class that is abstract because it has some abstract methods.

ReflectionClass::IS_EXPLICIT_ABSTRACT

Indicates class that is abstract because of its definition.

ReflectionClass::IS_FINAL

Indicates final class.

Table of Contents



ReflectionClass::__construct> <Reflection::getModifierNames
[edit] Last updated: Fri, 26 Apr 2013
 
add a note add a note User Contributed Notes ReflectionClass - [4 notes]
up
3
Anonymous
1 year ago
Unserialized reflection class cause error.

<?php
/**
 * abc
 */
class a{}

$ref = new ReflectionClass('a');
$ref = unserialize(serialize($ref));
var_dump($ref);
var_dump($ref->getDocComment());

// object(ReflectionClass)#2 (1) {
//   ["name"]=>
//   string(1) "a"
// }
// PHP Fatal error:  ReflectionClass::getDocComment(): Internal error: Failed to retrieve the reflection object
?>
up
1
danbettles at yahoo dot co dot uk
4 years ago
To reflect on a namespaced class in PHP 5.3, you must always specify the fully qualified name of the class - even if you've aliased the containing namespace using a "use" statement.

So instead of:

<?php
use App\Core as Core;
$oReflectionClass = new ReflectionClass('Core\Singleton');
?>

You would type:

<?php
use App\Core as Core;
$oReflectionClass = new ReflectionClass('App\Core\Singleton');
?>
up
-1
thecelavi at gmail dot com
3 years ago
Right:

<?php
use AppCore as Core;
$oReflectionClass = new ReflectionClass('App\Core\Singleton');
?>

Wrong:

<?php
use AppCore as Core;
$oReflectionClass = new ReflectionClass('\App\Core\Singleton');
?>
up
-2
snx
10 months ago
if you want to use an object method as a callback parameter for any asynchronous action you have to transfer the reflection method and the object itself.

consider doing something like this:
<?php
class Callback extends ReflectionMethod{

    protected
$oObject;
   
    public function
__construct($oObject, $sMethod){
       
parent::__construct($oObject, $sMethod);
       
$this->oObject = $oObject;
       
$this->setAccessible(true); //to access even protected methods..
   
}
   
    public function
invoke(){
       
$this->invokeArgs($this->oObject, func_get_args());
    }
   
}
?>

now you can easy create an reflector for the specific object method and pass it to any function...
<?php
class ClassA{
    public function
doSomething(){
       
$oCallback = new Callback($this, '_asyncCallback');
       
doAsyncCall($oCallback);
    }
    protected function
_asyncCallback(...){
       
//...
   
}
}

function
doAsyncCall($oCallback){
   
$oCallback->invoke(...);
}
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites