反射
- Reflection
- ReflectionClass
- ReflectionClass::__construct - 初始化 ReflectionClass 类
- ReflectionClass::getConstant - 获取类的指定常量
- ReflectionClass::getConstants - 获取类的所有常量
- ReflectionClass::getConstructor - 获取类的构造函数
- ReflectionClass::getDefaultProperties - 获取类的默认属性
- ReflectionClass::getDocComment - 获取类的文档注释
- ReflectionClass::getEndLine - 获取类的最后一行的行数
- ReflectionClass::getExtension - 根据已定义的类获取所在扩展的 ReflectionExtension 对象
- ReflectionClass::getExtensionName - 获取定义的类所在的扩展的名称
- ReflectionClass::getFileName - 获取定义类的文件名
- ReflectionClass::getInterfaceNames - 获取类的接口名称
- ReflectionClass::getInterfaces - 获取类的接口
- ReflectionClass::getMethod - 获取类的指定方法
- ReflectionClass::getMethods - 获取类的方法的数组
- ReflectionClass::getModifiers - 获取类的修饰符
- ReflectionClass::getName - 获取类名
- ReflectionClass::getNamespaceName - 获取类的命名空间的名称
- ReflectionClass::getParentClass - 获取父类
- ReflectionClass::getProperties - 获取类的一组属性
- ReflectionClass::getProperty - 获取类的指定属性
- ReflectionClass::getReflectionConstant - 获取类的指定常量
- ReflectionClass::getReflectionConstants - 获取类的所有常量
- ReflectionClass::getShortName - 获取类的短名
- ReflectionClass::getStartLine - 获取类的起始行号
- ReflectionClass::getStaticProperties - 获取类的静态属性
- ReflectionClass::getStaticPropertyValue - 获取类的指定静态属性的值
- ReflectionClass::getTraitAliases - 返回 Trait 别名的一个数组
- ReflectionClass::getTraitNames - 返回类所使用的 Trait 的名称的数组
- ReflectionClass::getTraits - 返回类所使用的 Trait 的数组
- ReflectionClass::hasConstant - 检查类的指定的常量是否已经定义
- ReflectionClass::hasMethod - 检查类的指定的方法是否已定义
- ReflectionClass::hasProperty - 检查类的指定的属性是否已定义
- ReflectionClass::implementsInterface - 检查类是否实现了指定的接口
- ReflectionClass::inNamespace - 检查类是否位于命名空间中
- ReflectionClass::isAbstract - 检查类是否是抽象类
- ReflectionClass::isAnonymous - 检查类是否是匿名类
- ReflectionClass::isCloneable - 检查类是否可复制
- ReflectionClass::isFinal - 检查类是否声明为 final
- ReflectionClass::isInstance - 检查是否是指定类的实例
- ReflectionClass::isInstantiable - 检查类是否可实例化
- ReflectionClass::isInterface - 检查类是否是接口
- ReflectionClass::isInternal - 检查类是否由扩展或核心在内部定义
- ReflectionClass::isIterable - 检查类是否可迭代
- ReflectionClass::isIterateable - 检查类是否可迭代
- ReflectionClass::isSubclassOf - 检查类是否为指定类的子类
- ReflectionClass::isTrait - 检查类是否是 Trait
- ReflectionClass::isUserDefined - 检查类是否是由用户定义的
- ReflectionClass::newInstance - 从指定的参数创建一个新的类实例
- ReflectionClass::newInstanceArgs - 从指定的参数创建一个新的类实例
- ReflectionClass::newInstanceWithoutConstructor - 创建一个新的类实例而不调用它的构造函数
- ReflectionClass::setStaticPropertyValue - 设置类的静态属性的值
- ReflectionClass::__toString - 返回 ReflectionClass 对象字符串的表示形式
- ReflectionClassConstant
- ReflectionClassConstant::__construct - 初始化 ReflectionClassConstant 类
- ReflectionClassConstant::getDeclaringClass - 获取指定的类常量声明所在的类
- ReflectionClassConstant::getDocComment - 获取指定的类常量的文档注释
- ReflectionClassConstant::getModifiers - 获取指定的类常量的修饰符
- ReflectionClassConstant::getName - 获取指定的类常量名
- ReflectionClassConstant::getValue - 获取指定的类常量的值
- ReflectionClassConstant::isPrivate - 检查指定的类常量是否声明为 private
- ReflectionClassConstant::isProtected - 检查指定的类常量是否声明为 protected
- ReflectionClassConstant::isPublic - 检查指定的类常量是否声明为 public
- ReflectionClassConstant::__toString - 返回 ReflectionClassConstant 对象字符串的表示形式
- ReflectionZendExtension
- ReflectionZendExtension::__construct - 初始化 ReflectionZendExtension 类
- ReflectionZendExtension::getAuthor - 获取 Zend 扩展的作者
- ReflectionZendExtension::getCopyright - 获取 Zend 扩展的版权信息
- ReflectionZendExtension::getName - 获取 Zend 扩展的名称
- ReflectionZendExtension::getURL - 获取 Zend 扩展的 URL
- ReflectionZendExtension::getVersion - 获取 Zend 扩展的版本
- ReflectionZendExtension::__toString - 返回 ReflectionZendExtension 对象字符串的表示形式
- ReflectionExtension
- ReflectionExtension::__construct - 初始化 ReflectionExtension 类
- ReflectionExtension::getClasses - 获取扩展中的类列表
- ReflectionExtension::getClassNames - 获取扩展中的类名称列表
- ReflectionExtension::getConstants - 获取扩展中的类常量
- ReflectionExtension::getDependencies - 获取扩展中的依赖
- ReflectionExtension::getFunctions - 获取扩展中的函数
- ReflectionExtension::getINIEntries - 获取扩展在 ini 文件中的配置
- ReflectionExtension::getName - 获取扩展的名称
- ReflectionExtension::getVersion - 获取扩展的版本号
- ReflectionExtension::info - 输出扩展的信息
- ReflectionExtension::isPersistent - 返回扩展是否持久化载入
- ReflectionExtension::isTemporary - 返回扩展是否是临时载入
- ReflectionExtension::__toString - 返回 ReflectionExtension 对象字符串的表示形式
- ReflectionFunction
- ReflectionFunction::__construct - 初始化 ReflectionFunction 类
- ReflectionFunction::getClosure - 返回指定的函数的动态创建的闭包
- ReflectionFunction::invoke - 调用指定的函数
- ReflectionFunction::invokeArgs - 调用指定的函数并将其参数作为数组传递
- ReflectionFunction::isDisabled - 检查指定的函数是否被禁用
- ReflectionFunction::__toString - 返回 ReflectionFunction 对象字符串的表示形式
- ReflectionFunctionAbstract
- ReflectionFunctionAbstract::getClosureScopeClass - 返回指定的函数的与闭包关联的范围
- ReflectionFunctionAbstract::getClosureThis - 返回指定的函数的的匿名函数
- ReflectionFunctionAbstract::getDocComment - 获取指定的函数的文档注释
- ReflectionFunctionAbstract::getEndLine - 获取指定的函数的结束行号
- ReflectionFunctionAbstract::getExtension - 获取指定的函数的扩展信息
- ReflectionFunctionAbstract::getExtensionName - 获取指定的函数的扩展名称
- ReflectionFunctionAbstract::getFileName - 获取指定的函数所在的文件名称
- ReflectionFunctionAbstract::getName - 获取指定的函数的名称
- ReflectionFunctionAbstract::getNamespaceName - 获取指定的函数的命名空间
- ReflectionFunctionAbstract::getNumberOfParameters - 获取指定的函数的参数数目
- ReflectionFunctionAbstract::getNumberOfRequiredParameters - 获取指定的函数的必须输入参数的个数
- ReflectionFunctionAbstract::getParameters - 获取指定的函数的参数
- ReflectionFunctionAbstract::getReturnType - 获取指定的函数的返回类型
- ReflectionFunctionAbstract::getShortName - 获取指定的函数的短名称
- ReflectionFunctionAbstract::getStartLine - 获取指定的函数的开始行号
- ReflectionFunctionAbstract::getStaticVariables - 获取指定的函数的静态变量
- ReflectionFunctionAbstract::hasReturnType - 检查指定的函数是否声明返回类型
- ReflectionFunctionAbstract::inNamespace - 检查指定的函数是否处于命名空间
- ReflectionFunctionAbstract::isClosure - 检查指定的函数是否是匿名函数
- ReflectionFunctionAbstract::isDeprecated - 检查指定的函数是否已经弃用
- ReflectionFunctionAbstract::isGenerator - 检查指定的函数是否是生成器
- ReflectionFunctionAbstract::isInternal - 检查指定的函数是否是内置函数
- ReflectionFunctionAbstract::isUserDefined - 检查指定的函数是否是用户自定义
- ReflectionFunctionAbstract::isVariadic - 检查指定的函数是否是可变函数
- ReflectionFunctionAbstract::returnsReference - 检查指定的函数是否返回引用
- ReflectionMethod
- ReflectionMethod::__construct - 初始化 ReflectionMethod 类
- ReflectionMethod::getClosure - 返回一个动态建立的方法调用接口,可以直接调用非公开方法
- ReflectionMethod::getDeclaringClass - 获取指定的类方法声明所在的类
- ReflectionMethod::getModifiers - 获取指定的类方法的修饰符
- ReflectionMethod::getPrototype - 返回指定的类方法的原型
- ReflectionMethod::invoke - 调用指定的类方法
- ReflectionMethod::invokeArgs - 调用指定的类方法
- ReflectionMethod::isAbstract - 判断指定的类方法是否是抽象方法
- ReflectionMethod::isConstructor - 判断指定的类方法是否是构造方法
- ReflectionMethod::isDestructor - 判断指定的类方法是否是析构方法
- ReflectionMethod::isFinal - 判断指定的类方法是否声明为 final
- ReflectionMethod::isPrivate - 判断指定的类方法是否声明为 private
- ReflectionMethod::isProtected - 判断指定的类方法是否声明为 protected
- ReflectionMethod::isPublic - 判断指定的类方法是否声明为 public
- ReflectionMethod::isStatic - 判断指定的类方法是否声明为 static
- ReflectionMethod::setAccessible - 设置指定的类方法是否可以访问
- ReflectionMethod::__toString - 返回 ReflectionMethod 对象字符串的表示形式
- ReflectionObject
- ReflectionParameter
- ReflectionParameter::__construct - 初始化 ReflectionParameter 类
- ReflectionParameter::allowsNull - 检查指定的参数是否允许为空
- ReflectionParameter::canBePassedByValue - 返回指定的参数是否可以按值传递
- ReflectionParameter::getClass - 获得指定的参数的类型提示的类
- ReflectionParameter::getDeclaringClass - 返回指定的参数声明所在的类
- ReflectionParameter::getDeclaringFunction - 返回指定的参数声明所在的函数
- ReflectionParameter::getDefaultValue - 返回指定的参数的默认值
- ReflectionParameter::getDefaultValueConstantName - 返回指定的参数的默认值的常量名称
- ReflectionParameter::getName - 获取指定的参数的名称
- ReflectionParameter::getPosition - 获取指定的参数的位置
- ReflectionParameter::getType - 获取指定的参数的类型
- ReflectionParameter::hasType - 检查指定的参数是否存在类型声明
- ReflectionParameter::isArray - 检查指定的参数是否是数组
- ReflectionParameter::isCallable - 检查指定的参数是否是可调用型
- ReflectionParameter::isDefaultValueAvailable - 检查指定的参数是否有默认值
- ReflectionParameter::isDefaultValueConstant - 检查指定的参数的默认是是否是常量
- ReflectionParameter::isOptional - 检查指定的参数是否是可选的
- ReflectionParameter::isPassedByReference - 返回指定的参数是否可以按引用传递
- ReflectionParameter::isVariadic - 返回指定的参数是否是可变参数
- ReflectionParameter::__toString - 返回 ReflectionParameter 对象字符串的表示形式
- ReflectionProperty
- ReflectionProperty::__construct - 初始化 ReflectionProperty 类
- ReflectionProperty::getDeclaringClass - 获取指定的类属性声明所在的类
- ReflectionProperty::getDocComment - 获取指定类属性的文档注释
- ReflectionProperty::getModifiers - 获取指定类属性的修饰符
- ReflectionProperty::getName - 获取指定类属性的名称
- ReflectionProperty::getType - 获取指定类属性的类型
- ReflectionProperty::getValue - 获取指定类属性的值
- ReflectionProperty::hasType - 检查指定的类属性是否存在类型声明
- ReflectionProperty::isDefault - 检查指定的类属性是否是默认属性
- ReflectionProperty::isInitialized - 检查指定的类属性是否已初始化
- ReflectionProperty::isPrivate - 检查指定的类属性是否声明为 private
- ReflectionProperty::isProtected - 检查指定的类属性是否声明为 protected
- ReflectionProperty::isPublic - 检查指定的类属性是否声明为 public
- ReflectionProperty::isStatic - 检查指定的类属性是否声明为 static
- ReflectionProperty::setAccessible - 设置指定的类属性是否可以访问
- ReflectionProperty::setValue - 设置指定的类属性的值
- ReflectionProperty::__toString - 返回 ReflectionProperty 对象字符串的表示形式
- ReflectionType
- ReflectionGenerator
- ReflectionGenerator::__construct - 初始化 ReflectionGenerator 类
- ReflectionGenerator::getExecutingFile - 获取指定的生成器所在的文件名
- ReflectionGenerator::getExecutingGenerator - 获取指定的生成器对象
- ReflectionGenerator::getExecutingLine - 获取指定的生成器所在的行号
- ReflectionGenerator::getFunction - 获取指定的生成器的函数名称
- ReflectionGenerator::getThis - 获取指定的生成器的 $this 的值
- ReflectionGenerator::getTrace - 获取指定的生成器的堆栈跟踪信息
Reflection
Reflection::getModifierNames
<?php
class Foo
{
/**
* Public method.
*
* @param void
* @return void
*/
final public function public()
{
//
}
/**
* Protected method.
*
* @param void
* @return void
*/
protected static function protected()
{
//
}
/**
* Private method.
*
* @param void
* @return void
*/
private function private()
{
//
}
}
var_dump(Reflection::getModifierNames((new ReflectionMethod('Foo', 'public'))->getModifiers())); // array(2) { [0]=> string(5) "final" [1]=> string(6) "public" }
var_dump(Reflection::getModifierNames((new ReflectionMethod('Foo', 'protected'))->getModifiers())); // array(2) { [0]=> string(9) "protected" [1]=> string(6) "static" }
var_dump(Reflection::getModifierNames((new ReflectionMethod('Foo', 'private'))->getModifiers())); // array(1) { [0]=> string(7) "private" }
ReflectionClass
ReflectionClass::__construct
<?php
class Foo
{
//
}
var_dump(new ReflectionClass('Foo')); // object(ReflectionClass)#1 (1) { ["name"]=> string(3) "Foo" }
var_dump(new ReflectionClass(new Foo())); // object(ReflectionClass)#1 (1) { ["name"]=> string(3) "Foo" }
ReflectionClass::getConstant
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getConstant('constant')); // bool(false)
var_dump($foo->getConstant('CONSTANT')); // string(3) "foo"
ReflectionClass::getConstants
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getConstants()); // array(1) { ["CONSTANT"]=> string(3) "foo" }
ReflectionClass::getConstructor
<?php
class Foo
{
/**
* Just a test constructor.
*
* @param void
* @return void
*/
public function __construct()
{
//
}
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getConstructor()); // object(ReflectionMethod)#2 (2) { ["name"]=> string(11) "__construct" ["class"]=> string(3) "Foo" }
ReflectionClass::getDefaultProperties
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $foo = 'foo';
/**
* Just a test property.
*
* @var string
*/
protected string $bar = 'bar';
/**
* Just a test property.
*
* @var string|null
*/
private ?string $baz;
/**
* Just a test property.
*
* @var string
*/
public static string $qux = 'qux';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getDefaultProperties()); // array(3) { ["qux"]=> string(3) "qux" ["foo"]=> string(3) "foo" ["bar"]=> string(3) "bar" }
ReflectionClass::getDocComment
<?php
/**
* Just a test class.
*/
class Foo
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getDocComment());
// string(29) "/**
// * Just a test class.
// */"
ReflectionClass::getEndLine
<?php
class Foo
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getEndLine()); // int(6)
ReflectionClass::getExtension
<?php
$foo = new ReflectionClass('ReflectionClass');
var_dump($foo->getExtension()); // object(ReflectionExtension)#2 (1) { ["name"]=> string(10) "Reflection" }
ReflectionClass::getExtensionName
<?php
$foo = new ReflectionClass('ReflectionClass');
var_dump($foo->getExtensionName()); // string(10) "Reflection"
ReflectionClass::getFileName
<?php
class Foo
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getFileName());
ReflectionClass::getInterfaceNames
<?php
interface Foo
{
//
}
interface Bar
{
//
}
class Baz implements Foo, Bar
{
//
}
$baz = new ReflectionClass('Baz');
var_dump($baz->getInterfaceNames()); // array(2) { [0]=> string(3) "Foo" [1]=> string(3) "Bar" }
ReflectionClass::getInterfaces
<?php
interface Foo
{
//
}
interface Bar
{
//
}
class Baz implements Foo, Bar
{
//
}
$baz = new ReflectionClass('Baz');
var_dump($baz->getInterfaces()); // array(2) { ["Foo"]=> object(ReflectionClass)#2 (1) { ["name"]=> string(3) "Foo" } ["Bar"]=> object(ReflectionClass)#3 (1) { ["name"]=> string(3) "Bar" } }
ReflectionClass::getMethod
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
public function method()
{
//
}
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getMethod('method')); // object(ReflectionMethod)#2 (2) { ["name"]=> string(6) "method" ["class"]=> string(3) "Foo" }
ReflectionClass::getMethods
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
public function method()
{
//
}
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getMethods()); // array(1) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(6) "method" ["class"]=> string(3) "Foo" } }
ReflectionClass::getModifiers
<?php
class Foo
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getModifiers()); // int(0)
ReflectionClass::getName
<?php
namespace Foo;
class Bar
{
//
}
$foo = new \ReflectionClass('stdClass');
var_dump($foo->getName()); // string(8) "stdClass"
$bar = new \ReflectionClass(Bar::class);
var_dump($bar->getName()); // string(7) "Foo\Bar"
ReflectionClass::getNamespaceName
<?php
namespace Foo;
class Bar
{
//
}
$foo = new \ReflectionClass('stdClass');
var_dump($foo->getNamespaceName()); // string(0) ""
$bar = new \ReflectionClass(Bar::class);
var_dump($bar->getNamespaceName()); // string(3) "Foo"
ReflectionClass::getParentClass
<?php
class Foo
{
//
}
class Bar extends Foo
{
//
}
$bar = new ReflectionClass('Bar');
var_dump($bar->getParentClass()); // object(ReflectionClass)#2 (1) { ["name"]=> string(3) "Foo" }
ReflectionClass::getProperties
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $foo = 'foo';
/**
* Just a test property.
*
* @var string
*/
protected string $bar = 'bar';
/**
* Just a test property.
*
* @var string
*/
private string $baz = 'baz';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getProperties()); // array(3) { [0]=> object(ReflectionProperty)#2 (2) { ["name"]=> string(3) "foo" ["class"]=> string(3) "Foo" } [1]=> object(ReflectionProperty)#3 (2) { ["name"]=> string(3) "bar" ["class"]=> string(3) "Foo" } [2]=> object(ReflectionProperty)#4 (2) { ["name"]=> string(3) "baz" ["class"]=> string(3) "Foo" } }
var_dump($foo->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED)); // array(2) { [0]=> object(ReflectionProperty)#4 (2) { ["name"]=> string(3) "foo" ["class"]=> string(3) "Foo" } [1]=> object(ReflectionProperty)#3 (2) { ["name"]=> string(3) "bar" ["class"]=> string(3) "Foo" } }
ReflectionClass::getProperty
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $foo = 'foo';
/**
* Just a test property.
*
* @var string
*/
protected string $bar = 'bar';
/**
* Just a test property.
*
* @var string
*/
private string $baz = 'baz';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getProperty('foo')); // object(ReflectionProperty)#2 (2) { ["name"]=> string(3) "foo" ["class"]=> string(3) "Foo" }
var_dump($foo->getProperty('bar')); // object(ReflectionProperty)#2 (2) { ["name"]=> string(3) "bar" ["class"]=> string(3) "Foo" }
var_dump($foo->getProperty('baz')); // object(ReflectionProperty)#2 (2) { ["name"]=> string(3) "baz" ["class"]=> string(3) "Foo" }
ReflectionClass::getReflectionConstant
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getReflectionConstant('constant')); // bool(false)
var_dump($foo->getReflectionConstant('CONSTANT')); // object(ReflectionClassConstant)#2 (2) { ["name"]=> string(8) "CONSTANT" ["class"]=> string(3) "Foo" }
ReflectionClass::getReflectionConstants
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getReflectionConstants()); // array(1) { [0]=> object(ReflectionClassConstant)#2 (2) { ["name"]=> string(8) "CONSTANT" ["class"]=> string(3) "Foo" } }
ReflectionClass::getShortName
<?php
namespace Foo;
class Bar
{
//
}
$foo = new \ReflectionClass('stdClass');
var_dump($foo->getShortName()); // string(8) "stdClass"
$bar = new \ReflectionClass('Foo\Bar');
var_dump($bar->getShortName()); // string(3) "Bar"
ReflectionClass::getStartLine
<?php
class Foo
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getStartLine()); // int(3)
ReflectionClass::getStaticProperties
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $foo = 'foo';
/**
* Just a test property.
*
* @var string
*/
protected string $bar = 'bar';
/**
* Just a test property.
*
* @var string|null
*/
private ?string $baz;
/**
* Just a test property.
*
* @var string
*/
public static string $qux = 'qux';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getStaticProperties()); // array(1) { ["qux"]=> string(3) "qux" }
ReflectionClass::getStaticPropertyValue
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public static string $foo = 'foo';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->getStaticPropertyValue('foo')); // string(3) "foo"
ReflectionClass::getTraitAliases
<?php
trait Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
public function method()
{
//
}
}
class Bar
{
use Foo
{
Foo::method as test;
}
}
$bar = new ReflectionClass('Bar');
var_dump($bar->getTraitAliases()); // array(1) { ["test"]=> string(11) "Foo::method" }
ReflectionClass::getTraitNames
<?php
trait Foo
{
//
}
trait Bar
{
//
}
class Baz
{
use Foo, Bar;
}
$baz = new ReflectionClass('Baz');
var_dump($baz->getTraitNames()); // array(2) { [0]=> string(3) "Foo" [1]=> string(3) "Bar" }
ReflectionClass::getTraits
<?php
trait Foo
{
//
}
trait Bar
{
//
}
class Baz
{
use Foo, Bar;
}
$baz = new ReflectionClass('Baz');
var_dump($baz->getTraits()); // array(2) { ["Foo"]=> object(ReflectionClass)#2 (1) { ["name"]=> string(3) "Foo" } ["Bar"]=> object(ReflectionClass)#3 (1) { ["name"]=> string(3) "Bar" } }
ReflectionClass::hasConstant
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->hasConstant('constant')); // bool(false)
var_dump($foo->hasConstant('CONSTANT')); // bool(true)
ReflectionClass::hasMethod
<?php
class Foo
{
/**
* Public method.
*
* @param void
* @return void
*/
public function public()
{
//
}
/**
* Protected method.
*
* @param void
* @return void
*/
protected function protected()
{
//
}
/**
* Private method.
*
* @param void
* @return void
*/
private function private()
{
//
}
}
$foo = new ReflectionClass('Foo');
var_dump($foo->hasMethod('public')); // bool(true)
var_dump($foo->hasMethod('protected')); // bool(true)
var_dump($foo->hasMethod('private')); // bool(true)
var_dump($foo->hasMethod('method')); // bool(false)
ReflectionClass::hasProperty
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $foo = 'foo';
/**
* Just a test property.
*
* @var string
*/
protected string $bar = 'bar';
/**
* Just a test property.
*
* @var string
*/
private string $baz = 'baz';
}
$foo = new ReflectionClass('Foo');
var_dump($foo->hasProperty('foo')); // bool(true)
var_dump($foo->hasProperty('bar')); // bool(true)
var_dump($foo->hasProperty('baz')); // bool(true)
var_dump($foo->hasProperty('property')); // bool(false)
ReflectionClass::implementsInterface
<?php
interface Foo
{
//
}
interface Bar
{
//
}
class Baz implements Foo
{
//
}
$baz = new ReflectionClass('Baz');
var_dump($baz->implementsInterface('Foo')); // bool(true)
var_dump($baz->implementsInterface('Bar')); // bool(false)
ReflectionClass::inNamespace
<?php
namespace Foo;
class Bar
{
//
}
$foo = new \ReflectionClass('stdClass');
var_dump($foo->inNamespace()); // bool(false)
$bar = new \ReflectionClass(Bar::class);
var_dump($bar->inNamespace()); // bool(true)
ReflectionClass::isAbstract
<?php
class Foo
{
//
}
abstract class Bar
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->isAbstract()); // bool(false)
$bar = new ReflectionClass('Bar');
var_dump($bar->isAbstract()); // bool(true)
ReflectionClass::isAnonymous
<?php
class Foo
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->isAnonymous()); // bool(false)
$bar = new class {
//
};
$bar = new ReflectionClass($bar);
var_dump($bar->isAnonymous()); // bool(true)
ReflectionClass::isCloneable
<?php
class Foo
{
//
}
class Bar
{
/**
* Do not clone this class.
*
* @param void
* @return void
*/
private function __clone()
{
//
}
}
$foo = new ReflectionClass('Foo');
var_dump($foo->isCloneable()); // bool(true)
$bar = new ReflectionClass('Bar');
var_dump($bar->isCloneable()); // bool(false)
ReflectionClass::isFinal
<?php
class Foo
{
//
}
final class Bar
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->isFinal()); // bool(false)
$bar = new ReflectionClass('Bar');
var_dump($bar->isFinal()); // bool(true)
ReflectionClass::isInstance
<?php
class Foo
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->isInstance(new Foo())); // bool(true)
var_dump((new Foo()) instanceof Foo); // bool(true)
var_dump(is_a(new Foo(), 'Foo')); // bool(true)
ReflectionClass::isInstantiable
<?php
class Foo
{
//
}
interface Bar
{
//
}
abstract class Baz
{
//
}
trait Qux
{
//
}
class Quux
{
/**
* Do not instantiate this class.
*
* @param void
* @return void
*/
private function __construct()
{
//
}
}
$foo = new ReflectionClass('Foo');
var_dump($foo->isInstantiable()); // bool(true)
$bar = new ReflectionClass('Bar');
var_dump($bar->isInstantiable()); // bool(false)
$baz = new ReflectionClass('Baz');
var_dump($baz->isInstantiable()); // bool(false)
$qux = new ReflectionClass('Qux');
var_dump($qux->isInstantiable()); // bool(false)
$quux = new ReflectionClass('Quux');
var_dump($quux->isInstantiable()); // bool(false)
ReflectionClass::isInterface
<?php
class Foo
{
//
}
interface Bar
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->isInterface()); // bool(false)
$bar = new ReflectionClass('Bar');
var_dump($bar->isInterface()); // bool(true)
ReflectionClass::isInternal
<?php
class Bar
{
//
}
$foo = new ReflectionClass('stdClass');
var_dump($foo->isInternal()); // bool(true)
$bar = new ReflectionClass('Bar');
var_dump($bar->isInternal()); // bool(false)
ReflectionClass::isIterable
<?php
class Foo
{
//
}
class Bar implements Iterator
{
/**
* Store an array.
*
* @var array
*/
private array $property;
/**
* Store an array to the property.
*
* @param array $array
* @return void
*/
public function __construct(array $array)
{
$this->property = $array;
}
/**
* Return the current element of the specified property.
*
* @param void
* @return int
*/
public function current(): int
{
var_dump(__METHOD__);
return current($this->property);
}
/**
* Advance the internal pointer of the specified property.
*
* @param void
* @return void
*/
public function next()
{
var_dump(__METHOD__);
next($this->property);
}
/**
* Return the current key of the specified property.
*
* @param void
* @return int
*/
public function key(): int
{
var_dump(__METHOD__);
return key($this->property);
}
/**
* Return the validity of the current position of the specified property.
*
* @param void
* @return bool
*/
public function valid(): bool
{
var_dump(__METHOD__);
return current($this->property) !== false;
}
/**
* Set the internal pointer of the specified property to the first element.
*
* @param void
* @return void
*/
public function rewind()
{
var_dump(__METHOD__);
reset($this->property);
}
}
class Baz implements IteratorAggregate
{
/**
* Just a test property.
*
* @var string
*/
public string $foo = 'foo';
/**
* Just a test property.
*
* @var string
*/
public string $bar = 'bar';
/**
* Just a test property.
*
* @var string
*/
public string $baz = 'baz';
/**
* Just a test property.
*
* @var string
*/
public string $qux = 'qux';
/**
* Return an external iterator.
*
* @param void
* @return ArrayIterator
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this);
}
}
class Qux extends ArrayObject
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->isIterable()); // bool(false)
$bar = new ReflectionClass('Bar');
var_dump($bar->isIterable()); // bool(true)
$baz = new ReflectionClass('Baz');
var_dump($baz->isIterable()); // bool(true)
$qux = new ReflectionClass('Qux');
var_dump($qux->isIterable()); // bool(true)
ReflectionClass::isIterateable
<?php
class Foo
{
//
}
class Bar implements Iterator
{
/**
* Store an array.
*
* @var array
*/
private array $property;
/**
* Store an array to the property.
*
* @param array $array
* @return void
*/
public function __construct(array $array)
{
$this->property = $array;
}
/**
* Return the current element of the specified property.
*
* @param void
* @return int
*/
public function current(): int
{
var_dump(__METHOD__);
return current($this->property);
}
/**
* Advance the internal pointer of the specified property.
*
* @param void
* @return void
*/
public function next()
{
var_dump(__METHOD__);
next($this->property);
}
/**
* Return the current key of the specified property.
*
* @param void
* @return int
*/
public function key(): int
{
var_dump(__METHOD__);
return key($this->property);
}
/**
* Return the validity of the current position of the specified property.
*
* @param void
* @return bool
*/
public function valid(): bool
{
var_dump(__METHOD__);
return current($this->property) !== false;
}
/**
* Set the internal pointer of the specified property to the first element.
*
* @param void
* @return void
*/
public function rewind()
{
var_dump(__METHOD__);
reset($this->property);
}
}
class Baz implements IteratorAggregate
{
/**
* Just a test property.
*
* @var string
*/
public string $foo = 'foo';
/**
* Just a test property.
*
* @var string
*/
public string $bar = 'bar';
/**
* Just a test property.
*
* @var string
*/
public string $baz = 'baz';
/**
* Just a test property.
*
* @var string
*/
public string $qux = 'qux';
/**
* Return an external iterator.
*
* @param void
* @return ArrayIterator
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this);
}
}
class Qux extends ArrayObject
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->isIterateable()); // bool(false)
$bar = new ReflectionClass('Bar');
var_dump($bar->isIterateable()); // bool(true)
$baz = new ReflectionClass('Baz');
var_dump($baz->isIterateable()); // bool(true)
$qux = new ReflectionClass('Qux');
var_dump($qux->isIterateable()); // bool(true)
ReflectionClass::isSubclassOf
<?php
class Foo
{
//
}
class Bar
{
//
}
class Baz extends Bar
{
//
}
$baz = new ReflectionClass('Baz');
var_dump($baz->isSubclassOf('Bar')); // bool(true)
var_dump($baz->isSubclassOf('Foo')); // bool(false)
ReflectionClass::isTrait
<?php
class Foo
{
//
}
trait Bar
{
//
}
$foo = new ReflectionClass('Foo');
var_dump($foo->isTrait()); // bool(false)
$bar = new ReflectionClass('Bar');
var_dump($bar->isTrait()); // bool(true)
ReflectionClass::isUserDefined
<?php
class Bar
{
//
}
$foo = new ReflectionClass('stdClass');
var_dump($foo->isUserDefined()); // bool(false)
$bar = new ReflectionClass('Bar');
var_dump($bar->isUserDefined()); // bool(true)
ReflectionClass::newInstance
<?php
class Foo
{
/**
* Just a test property.
*
* @var string|null
*/
public ?string $foo;
/**
* Just a test property.
*
* @var string|null
*/
public ?string $bar;
/**
* Initialize the value of the property.
*
* @param string|null $foo
* @param string|null $bar
* @return void
*/
public function __construct(?string $foo = null, ?string $bar = null)
{
$this->foo = $foo;
$this->bar = $bar;
}
}
$foo = new ReflectionClass('Foo');
$foo = $foo->newInstance();
var_dump($foo->foo); // NULL
var_dump($foo->bar); // NULL
$foo = new ReflectionClass('Foo');
$foo = $foo->newInstance('foo');
var_dump($foo->foo); // string(3) "foo"
var_dump($foo->bar); // NULL
$foo = new ReflectionClass('Foo');
$foo = $foo->newInstance('foo', 'bar');
var_dump($foo->foo); // string(3) "foo"
var_dump($foo->bar); // string(3) "bar"
ReflectionClass::newInstanceArgs
<?php
class Foo
{
/**
* Just a test property.
*
* @var string|null
*/
public ?string $foo;
/**
* Just a test property.
*
* @var string|null
*/
public ?string $bar;
/**
* Initialize the value of the property.
*
* @param string|null $value
* @return void
*/
public function __construct(?string ...$value)
{
$this->foo = isset($value[0]) ? $value[0] : null;
$this->bar = isset($value[1]) ? $value[1] : null;
}
}
$foo = new ReflectionClass('Foo');
$foo = $foo->newInstanceArgs();
var_dump($foo->foo); // NULL
var_dump($foo->bar); // NULL
$foo = new ReflectionClass('Foo');
$foo = $foo->newInstanceArgs(['foo']);
var_dump($foo->foo); // string(3) "foo"
var_dump($foo->bar); // NULL
$foo = new ReflectionClass('Foo');
$foo = $foo->newInstanceArgs(['foo', 'bar']);
var_dump($foo->foo); // string(3) "foo"
var_dump($foo->bar); // string(3) "bar"
ReflectionClass::newInstanceWithoutConstructor
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $foo = 'foo';
/**
* Just a test property.
*
* @var string
*/
public string $bar = 'bar';
/**
* Change the value of the property.
*
* @param void
* @return void
*/
public function __construct()
{
list($this->foo, $this->bar) = ['FOO', 'BAR'];
}
}
$foo = new ReflectionClass('Foo');
$foo = $foo->newInstanceWithoutConstructor();
var_dump($foo->foo); // string(3) "foo"
var_dump($foo->bar); // string(3) "bar"
ReflectionClass::setStaticPropertyValue
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public static string $foo = 'foo';
}
$foo = new ReflectionClass('Foo');
$foo->setStaticPropertyValue('foo', 'bar');
var_dump((new Foo())::$foo); // string(3) "bar"
ReflectionClass::__toString
<?php
class Foo
{
//
}
$foo = new ReflectionClass('Foo');
echo $foo;
print $foo;
ReflectionClassConstant
ReflectionClassConstant::__construct
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
var_dump(new ReflectionClassConstant('Foo', 'CONSTANT')); // object(ReflectionClassConstant)#1 (2) { ["name"]=> string(8) "CONSTANT" ["class"]=> string(3) "Foo" }
ReflectionClassConstant::getDeclaringClass
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClassConstant('Foo', 'CONSTANT');
var_dump($foo->getDeclaringClass()); // object(ReflectionClass)#2 (1) { ["name"]=> string(3) "Foo" }
ReflectionClassConstant::getDocComment
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClassConstant('Foo', 'CONSTANT');
var_dump($foo->getDocComment());
// string(66) "/**
// * Just a test constant.
// *
// * @var string
// */"
ReflectionClassConstant::getModifiers
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClassConstant('Foo', 'CONSTANT');
var_dump($foo->getModifiers()); // int(1)
ReflectionClassConstant::getName
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClassConstant('Foo', 'CONSTANT');
var_dump($foo->getName()); // string(8) "CONSTANT"
ReflectionClassConstant::getValue
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClassConstant('Foo', 'CONSTANT');
var_dump($foo->getValue()); // string(3) "foo"
ReflectionClassConstant::isPrivate
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
private const CONSTANT = 'foo';
}
$foo = new ReflectionClassConstant('Foo', 'CONSTANT');
var_dump($foo->isPrivate()); // bool(true)
ReflectionClassConstant::isProtected
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
protected const CONSTANT = 'foo';
}
$foo = new ReflectionClassConstant('Foo', 'CONSTANT');
var_dump($foo->isProtected()); // bool(true)
ReflectionClassConstant::isPublic
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClassConstant('Foo', 'CONSTANT');
var_dump($foo->isPublic()); // bool(true)
ReflectionClassConstant::__toString
<?php
class Foo
{
/**
* Just a test constant.
*
* @var string
*/
public const CONSTANT = 'foo';
}
$foo = new ReflectionClassConstant('Foo', 'CONSTANT');
echo $foo; // Constant [ public string CONSTANT ] { foo }
print $foo; // Constant [ public string CONSTANT ] { foo }
ReflectionZendExtension
ReflectionZendExtension::__construct
<?php
var_dump(new ReflectionZendExtension('Zend OPcache')); // object(ReflectionZendExtension)#1 (1) { ["name"]=> string(12) "Zend OPcache" }
ReflectionZendExtension::getAuthor
<?php
$foo = new ReflectionZendExtension('Zend OPcache');
var_dump($foo->getAuthor()); // string(17) "Zend Technologies"
ReflectionZendExtension::getCopyright
<?php
$foo = new ReflectionZendExtension('Zend OPcache');
var_dump($foo->getCopyright()); // string(13) "Copyright (c)"
ReflectionZendExtension::getName
<?php
$foo = new ReflectionZendExtension('Zend OPcache');
var_dump($foo->getName()); // string(12) "Zend OPcache"
ReflectionZendExtension::getURL
<?php
$foo = new ReflectionZendExtension('Zend OPcache');
var_dump($foo->getURL()); // string(20) "http://www.zend.com/"
ReflectionZendExtension::getVersion
<?php
$foo = new ReflectionZendExtension('Zend OPcache');
var_dump($foo->getVersion());
ReflectionZendExtension::__toString
<?php
$foo = new ReflectionZendExtension('Zend OPcache');
echo $foo;
print $foo;
ReflectionExtension
ReflectionExtension::__construct
<?php
var_dump(new ReflectionExtension('Reflection')); // object(ReflectionExtension)#1 (1) { ["name"]=> string(10) "Reflection" }
ReflectionExtension::getClasses
<?php
$foo = new ReflectionExtension('Reflection');
var_dump($foo->getClasses());
ReflectionExtension::getClassNames
<?php
$foo = new ReflectionExtension('Reflection');
var_dump($foo->getClassNames());
ReflectionExtension::getConstants
<?php
$foo = new ReflectionExtension('Reflection');
var_dump($foo->getConstants());
ReflectionExtension::getDependencies
<?php
$foo = new ReflectionExtension('Reflection');
var_dump($foo->getDependencies());
ReflectionExtension::getFunctions
<?php
$foo = new ReflectionExtension('Reflection');
var_dump($foo->getFunctions());
ReflectionExtension::getINIEntries
<?php
$foo = new ReflectionExtension('Reflection');
var_dump($foo->getINIEntries());
ReflectionExtension::getName
<?php
$foo = new ReflectionExtension('Reflection');
var_dump($foo->getName()); // string(10) "Reflection"
ReflectionExtension::getVersion
<?php
$foo = new ReflectionExtension('Reflection');
var_dump($foo->getVersion());
ReflectionExtension::info
<?php
$foo = new ReflectionExtension('Reflection');
$foo->info();
ReflectionExtension::isPersistent
<?php
$foo = new ReflectionExtension('Reflection');
var_dump($foo->isPersistent()); // bool(true)
ReflectionExtension::isTemporary
<?php
$foo = new ReflectionExtension('Reflection');
var_dump($foo->isTemporary()); // bool(false)
ReflectionExtension::__toString
<?php
$foo = new ReflectionExtension('Reflection');
echo $foo;
print $foo;
ReflectionFunction
ReflectionFunction::__construct
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
/**
* Just a test function.
*
* @param void
* @return void
*/
$foo = function () {
//
};
var_dump(new ReflectionFunction('foo')); // object(ReflectionFunction)#2 (1) { ["name"]=> string(3) "foo" }
var_dump(new ReflectionFunction($foo)); // object(ReflectionFunction)#2 (1) { ["name"]=> string(9) "{closure}" }
ReflectionFunction::getClosure
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo(): string
{
return 'foo';
}
$foo = new ReflectionFunction('foo');
var_dump(($foo->getClosure())()); // string(3) "foo"
ReflectionFunction::invoke
<?php
/**
* Calculate the sum of two integers.
*
* @param int $a
* @param int $b
* @return int
*/
function foo(int $a, int $b): int
{
return $a + $b;
}
$foo = new ReflectionFunction('foo');
var_dump($foo->invoke(2, 3)); // int(5)
ReflectionFunction::invokeArgs
<?php
/**
* Calculate the sum of all integers.
*
* @param int $number
* @return int
*/
function foo(int ...$number): int
{
$sum = 0;
foreach ($number as $value) {
$sum += $value;
}
return $sum;
}
$foo = new ReflectionFunction('foo');
var_dump($foo->invokeArgs([1, 2, 3])); // int(6)
ReflectionFunction::isDisabled
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->isDisabled()); // bool(false)
ReflectionFunction::__toString
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
echo $foo;
print $foo;
ReflectionFunctionAbstract
ReflectionFunctionAbstract::getClosureScopeClass
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getClosureScopeClass()); // NULL
ReflectionFunctionAbstract::getClosureThis
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getClosureThis()); // NULL
ReflectionFunctionAbstract::getDocComment
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getDocComment());
// string(67) "/**
// * Just a test function.
// *
// * @param void
// * @return void
// */"
ReflectionFunctionAbstract::getEndLine
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getEndLine()); // int(12)
ReflectionFunctionAbstract::getExtension
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getExtension()); // NULL
$foo = new ReflectionFunction('mb_strlen');
var_dump($foo->getExtension()); // object(ReflectionExtension)#1 (1) { ["name"]=> string(8) "mbstring" }
ReflectionFunctionAbstract::getExtensionName
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getExtensionName()); // bool(false)
$foo = new ReflectionFunction('mb_strlen');
var_dump($foo->getExtensionName()); // string(8) "mbstring"
ReflectionFunctionAbstract::getFileName
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getFileName());
ReflectionFunctionAbstract::getName
<?php
namespace Foo;
/**
* Just a test function.
*
* @param void
* @return void
*/
function bar()
{
//
}
$foo = new \ReflectionFunction('var_dump');
var_dump($foo->getName()); // string(8) "var_dump"
$bar = new \ReflectionFunction('Foo\bar');
var_dump($bar->getName()); // string(7) "Foo\bar"
ReflectionFunctionAbstract::getNamespaceName
<?php
namespace Foo;
/**
* Just a test function.
*
* @param void
* @return void
*/
function bar()
{
//
}
$foo = new \ReflectionFunction('var_dump');
var_dump($foo->getNamespaceName()); // string(0) ""
$bar = new \ReflectionFunction('Foo\bar');
var_dump($bar->getNamespaceName()); // string(3) "Foo"
ReflectionFunctionAbstract::getNumberOfParameters
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getNumberOfParameters()); // int(0)
$foo = new ReflectionFunction('var_dump');
var_dump($foo->getNumberOfParameters()); // int(1)
ReflectionFunctionAbstract::getNumberOfRequiredParameters
<?php
/**
* Just a test function.
*
* @param string $string
* @return string
*/
function foo(string $string = 'foo'): string
{
return $string;
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getNumberOfRequiredParameters()); // int(0)
$foo = new ReflectionFunction('var_dump');
var_dump($foo->getNumberOfRequiredParameters()); // int(1)
ReflectionFunctionAbstract::getParameters
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
/**
* Calculate the sum of two integers.
*
* @param int $a
* @param int $b
* @return int
*/
function bar(int $a, int $b): int
{
return $a + $b;
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getParameters()); // array(0) { }
$bar = new ReflectionFunction('bar');
var_dump($bar->getParameters()); // array(2) { [0]=> object(ReflectionParameter)#3 (1) { ["name"]=> string(1) "a" } [1]=> object(ReflectionParameter)#4 (1) { ["name"]=> string(1) "b" } }
ReflectionFunctionAbstract::getReturnType
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
/**
* Just a test function.
*
* @param void
* @return string
*/
function bar(): string
{
return 'bar';
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getReturnType()); // NULL
$bar = new ReflectionFunction('bar');
var_dump($bar->getReturnType()); // object(ReflectionNamedType)#3 (0) { }
ReflectionFunctionAbstract::getShortName
<?php
namespace Foo;
/**
* Just a test function.
*
* @param void
* @return void
*/
function bar()
{
//
}
$foo = new \ReflectionFunction('var_dump');
var_dump($foo->getShortName()); // string(8) "var_dump"
$bar = new \ReflectionFunction('Foo\bar');
var_dump($bar->getShortName()); // string(3) "bar"
ReflectionFunctionAbstract::getStartLine
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getStartLine()); // int(9)
ReflectionFunctionAbstract::getStaticVariables
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
static $a = 2;
static $b = 3;
}
$foo = new ReflectionFunction('foo');
var_dump($foo->getStaticVariables()); // array(2) { ["a"]=> int(2) ["b"]=> int(3) }
ReflectionFunctionAbstract::hasReturnType
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
/**
* Just a test function.
*
* @param void
* @return string
*/
function bar(): string
{
return 'bar';
}
$foo = new ReflectionFunction('foo');
var_dump($foo->hasReturnType()); // bool(false)
$bar = new ReflectionFunction('bar');
var_dump($bar->hasReturnType()); // bool(true)
ReflectionFunctionAbstract::inNamespace
<?php
namespace Foo;
/**
* Just a test function.
*
* @param void
* @return void
*/
function bar()
{
//
}
$foo = new \ReflectionFunction('var_dump');
var_dump($foo->inNamespace()); // bool(false)
$bar = new \ReflectionFunction('Foo\bar');
var_dump($bar->inNamespace()); // bool(true)
ReflectionFunctionAbstract::isClosure
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
/**
* Just a test function.
*
* @param void
* @return void
*/
$bar = function () {
//
};
$foo = new ReflectionFunction('foo');
var_dump($foo->isClosure()); // bool(false)
$bar = new ReflectionFunction($bar);
var_dump($bar->isClosure()); // bool(true)
ReflectionFunctionAbstract::isDeprecated
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->isDeprecated()); // bool(false)
ReflectionFunctionAbstract::isGenerator
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
/**
* Yielding test value.
*
* @param void
* @return void
*/
function bar()
{
yield 1;
}
$foo = new ReflectionFunction('foo');
var_dump($foo->isGenerator()); // bool(false)
$foo = new ReflectionFunction('bar');
var_dump($foo->isGenerator()); // bool(true)
ReflectionFunctionAbstract::isInternal
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->isInternal()); // bool(false)
$foo = new ReflectionFunction('var_dump');
var_dump($foo->isInternal()); // bool(true)
ReflectionFunctionAbstract::isUserDefined
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->isUserDefined()); // bool(true)
$foo = new ReflectionFunction('var_dump');
var_dump($foo->isUserDefined()); // bool(false)
ReflectionFunctionAbstract::isVariadic
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
$foo = new ReflectionFunction('foo');
var_dump($foo->isVariadic()); // bool(false)
ReflectionFunctionAbstract::returnsReference
<?php
/**
* Just a test function.
*
* @param void
* @return void
*/
function foo()
{
//
}
/**
* Return a reference.
*
* @param void
* @return int
*/
function &bar(): int
{
static $a = 2;
return $a++;
}
$foo = new ReflectionFunction('foo');
var_dump($foo->returnsReference()); // bool(false)
$bar = new ReflectionFunction('bar');
var_dump($bar->returnsReference()); // bool(true)
ReflectionMethod
ReflectionMethod::__construct
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
public function method()
{
//
}
}
var_dump(new ReflectionMethod('Foo', 'method'));
var_dump(new ReflectionMethod('Foo::method'));
ReflectionMethod::getClosure
<?php
class Foo
{
/**
* Public method.
*
* @param void
* @return string
*/
public function public(): string
{
return 'public';
}
/**
* Protected method.
*
* @param void
* @return string
*/
protected function protected(): string
{
return 'protected';
}
/**
* Private method.
*
* @param void
* @return string
*/
private function private(): string
{
return 'private';
}
}
$foo = new ReflectionMethod('Foo', 'public');
var_dump(($foo->getClosure(new Foo()))()); // string(6) "public"
$foo = new ReflectionMethod('Foo', 'protected');
var_dump(($foo->getClosure(new Foo()))()); // string(9) "protected"
$foo = new ReflectionMethod('Foo', 'private');
var_dump(($foo->getClosure(new Foo()))()); // string(7) "private"
ReflectionMethod::getDeclaringClass
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
public function method()
{
//
}
}
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->getDeclaringClass()); // object(ReflectionClass)#2 (1) { ["name"]=> string(3) "Foo" }
ReflectionMethod::getModifiers
<?php
class Foo
{
/**
* Public method.
*
* @param void
* @return void
*/
final public function public()
{
//
}
/**
* Protected method.
*
* @param void
* @return void
*/
protected static function protected()
{
//
}
/**
* Private method.
*
* @param void
* @return void
*/
private function private()
{
//
}
}
$foo = new ReflectionMethod('Foo', 'public');
var_dump($foo->getModifiers()); // int(33)
$foo = new ReflectionMethod('Foo', 'protected');
var_dump($foo->getModifiers()); // int(18)
$foo = new ReflectionMethod('Foo', 'private');
var_dump($foo->getModifiers()); // int(4)
ReflectionMethod::getPrototype
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
public function method()
{
//
}
}
class Bar extends Foo
{
/**
* Override the parent method.
*
* @param void
* @return string
*/
public function method(): string
{
return 'bar';
}
}
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->getPrototype()); // PHP Fatal error: Uncaught ReflectionException: Method Foo::method does not have a prototype.
$bar = new ReflectionMethod('Bar', 'method');
var_dump($bar->getPrototype()); // object(ReflectionMethod)#3 (2) { ["name"]=> string(6) "method" ["class"]=> string(3) "Foo" }
ReflectionMethod::invoke
<?php
class Foo
{
/**
* Calculate the sum of two integers.
*
* @param int $a
* @param int $b
* @return int
*/
public function method(int $a, int $b): int
{
return $a + $b;
}
}
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->invoke(new Foo(), 2, 3)); // int(5)
ReflectionMethod::invokeArgs
<?php
class Foo
{
/**
* Calculate the sum of all integers.
*
* @param array $number
* @return int
*/
public function method(array $number): int
{
$sum = 0;
foreach ($number as $value) {
$sum += $value;
}
return $sum;
}
}
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->invoke(new Foo(), [1, 2, 3])); // int(6)
ReflectionMethod::isAbstract
<?php
abstract class Foo
{
/**
* Just an abstract method.
*
* @param void
* @return void
*/
abstract public function method();
}
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->isAbstract()); // bool(true)
ReflectionMethod::isConstructor
<?php
class Foo
{
/**
* Just a test constructor.
*
* @param void
* @return void
*/
public function __construct()
{
//
}
/**
* Just a test method.
*
* @param void
* @return void
*/
public function method()
{
//
}
}
$foo = new ReflectionMethod('Foo', '__construct');
var_dump($foo->isConstructor()); // bool(true)
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->isConstructor()); // bool(false)
ReflectionMethod::isDestructor
<?php
class Foo
{
/**
* Just a test destructor.
*
* @param void
* @return void
*/
public function __destruct()
{
//
}
/**
* Just a test method.
*
* @param void
* @return void
*/
public function method()
{
//
}
}
$foo = new ReflectionMethod('Foo', '__destruct');
var_dump($foo->isDestructor()); // bool(true)
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->isDestructor()); // bool(false)
ReflectionMethod::isFinal
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
final public function method()
{
//
}
}
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->isFinal()); // bool(true)
ReflectionMethod::isPrivate
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
private function method()
{
//
}
}
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->isPrivate()); // bool(true)
ReflectionMethod::isProtected
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
protected function method()
{
//
}
}
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->isProtected()); // bool(true)
ReflectionMethod::isPublic
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
public function method()
{
//
}
}
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->isPublic()); // bool(true)
ReflectionMethod::isStatic
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
public static function method()
{
//
}
}
$foo = new ReflectionMethod('Foo', 'method');
var_dump($foo->isStatic()); // bool(true)
ReflectionMethod::setAccessible
<?php
class Foo
{
/**
* Calculate the sum of two integers.
*
* @param int $a
* @param int $b
* @return int
*/
private function method(int $a, int $b): int
{
return $a + $b;
}
}
$foo = new ReflectionMethod('Foo', 'method');
$foo->setAccessible(true);
var_dump($foo->invoke(new Foo(), 2, 3)); // int(5)
ReflectionMethod::__toString
<?php
class Foo
{
/**
* Just a test method.
*
* @param void
* @return void
*/
public function method()
{
//
}
}
$foo = new ReflectionMethod('Foo', 'method');
echo $foo;
print $foo;
ReflectionObject
ReflectionObject::__construct
<?php
class Foo
{
//
}
var_dump(new ReflectionObject(new Foo())); // object(ReflectionObject)#1 (1) { ["name"]=> string(3) "Foo" }
ReflectionParameter
ReflectionParameter::__construct
<?php
/**
* Calculate the sum of two integers.
*
* @param int $a
* @param int $b
* @return int
*/
function foo(int $a, int $b): int
{
return $a + $b;
}
var_dump(new ReflectionParameter('foo', 'a')); // object(ReflectionParameter)#1 (1) { ["name"]=> string(1) "a" }
var_dump(new ReflectionParameter('foo', 0)); // object(ReflectionParameter)#1 (1) { ["name"]=> string(1) "a" }
var_dump(new ReflectionParameter('foo', 'b')); // object(ReflectionParameter)#1 (1) { ["name"]=> string(1) "b" }
var_dump(new ReflectionParameter('foo', 1)); // object(ReflectionParameter)#1 (1) { ["name"]=> string(1) "b" }
ReflectionParameter::allowsNull
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
/**
* Just a test function.
*
* @param string|null $string
* @return void
*/
function bar(?string $string = null)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->allowsNull()); // bool(false)
$bar = new ReflectionParameter('bar', 'string');
var_dump($bar->allowsNull()); // bool(true)
ReflectionParameter::canBePassedByValue
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
/**
* Just a test function.
*
* @param string &$string
* @return void
*/
function bar(string &$string)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->canBePassedByValue()); // bool(true)
$bar = new ReflectionParameter('bar', 'string');
var_dump($bar->canBePassedByValue()); // bool(false)
ReflectionParameter::getClass
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
/**
* Just a test function.
*
* @param Exception $exception
* @return void
*/
function bar(Exception $exception)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->getClass()); // NULL
$bar = new ReflectionParameter('bar', 'exception');
var_dump($bar->getClass()); // object(ReflectionClass)#3 (1) { ["name"]=> string(9) "Exception" }
ReflectionParameter::getDeclaringClass
<?php
class Foo
{
/**
* Just a test method.
*
* @param string $string
* @return void
*/
public function method(string $string)
{
//
}
}
$foo = new ReflectionParameter([new Foo(), 'method'], 'string');
var_dump($foo->getDeclaringClass()); // object(ReflectionClass)#2 (1) { ["name"]=> string(3) "Foo" }
ReflectionParameter::getDeclaringFunction
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->getDeclaringFunction()); // object(ReflectionFunction)#2 (1) { ["name"]=> string(3) "foo" }
ReflectionParameter::getDefaultValue
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function bar(string $string = 'bar')
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->getDefaultValue()); // PHP Fatal error: Uncaught ReflectionException: Internal error: Failed to retrieve the default value.
$bar = new ReflectionParameter('bar', 'string');
var_dump($bar->getDefaultValue()); // string(3) "bar"
ReflectionParameter::getDefaultValueConstantName
<?php
/**
* Just a test function.
*
* @param int $number
* @return void
*/
function foo(int $number = PHP_INI_MIN)
{
//
}
$foo = new ReflectionParameter('foo', 'number');
var_dump($foo->getDefaultValueConstantName()); // string(11) "PHP_INI_MIN"
ReflectionParameter::getName
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->getName()); // string(6) "string"
ReflectionParameter::getPosition
<?php
/**
* Calculate the sum of two integers.
*
* @param int $a
* @param int $b
* @return int
*/
function foo(int $a, int $b): int
{
return $a + $b;
}
$foo = new ReflectionParameter('foo', 'a');
var_dump($foo->getPosition()); // int(0)
$foo = new ReflectionParameter('foo', 'b');
var_dump($foo->getPosition()); // int(1)
ReflectionParameter::getType
<?php
/**
* Just a test function.
*
* @param int $number
* @param string $string
* @return void
*/
function foo(int $number, string $string)
{
//
}
$foo = new ReflectionParameter('foo', 'number');
var_dump($foo->getType()); // object(ReflectionNamedType)#2 (0) { }
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->getType()); // object(ReflectionNamedType)#1 (0) { }
ReflectionParameter::hasType
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->hasType()); // bool(true)
ReflectionParameter::isArray
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
/**
* Just a test function.
*
* @param array $array
* @return void
*/
function bar(array $array)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->isArray()); // bool(false)
$bar = new ReflectionParameter('bar', 'array');
var_dump($bar->isArray()); // bool(true)
ReflectionParameter::isCallable
<?php
$foo = new ReflectionParameter('array_map', 0);
var_dump($foo->isCallable()); // bool(false)
ReflectionParameter::isDefaultValueAvailable
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function bar(string $string = 'bar')
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->isDefaultValueAvailable()); // bool(false)
$bar = new ReflectionParameter('bar', 'string');
var_dump($bar->isDefaultValueAvailable()); // bool(true)
ReflectionParameter::isDefaultValueConstant
<?php
/**
* Just a test function.
*
* @param int $number
* @return void
*/
function foo(int $number = PHP_INI_MIN)
{
//
}
$foo = new ReflectionParameter('foo', 'number');
var_dump($foo->isDefaultValueConstant()); // bool(true)
ReflectionParameter::isOptional
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function bar(string $string = 'bar')
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->isOptional()); // bool(false)
$bar = new ReflectionParameter('bar', 'string');
var_dump($bar->isOptional()); // bool(true)
ReflectionParameter::isPassedByReference
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
/**
* Just a test function.
*
* @param string &$string
* @return void
*/
function bar(string &$string)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->isPassedByReference()); // bool(false)
$bar = new ReflectionParameter('bar', 'string');
var_dump($bar->isPassedByReference()); // bool(true)
ReflectionParameter::isVariadic
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->isVariadic()); // bool(false)
ReflectionParameter::__toString
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
echo $foo; // Parameter #0 [ string $string ]
print $foo; // Parameter #0 [ string $string ]
ReflectionProperty
ReflectionProperty::__construct
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $property = 'foo';
}
var_dump(new ReflectionProperty('Foo', 'property')); // object(ReflectionProperty)#1 (2) { ["name"]=> string(8) "property" ["class"]=> string(3) "Foo" }
ReflectionProperty::getDeclaringClass
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
var_dump($foo->getDeclaringClass()); // object(ReflectionClass)#2 (1) { ["name"]=> string(3) "Foo" }
ReflectionProperty::getDocComment
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
var_dump($foo->getDocComment());
// string(66) "/**
// * Just a test property.
// *
// * @var string
// */"
ReflectionProperty::getModifiers
<?php
class Foo
{
/**
* Public property.
*
* @var string
*/
public static string $public = 'public';
/**
* Protected property.
*
* @var string
*/
protected string $protected = 'protected';
/**
* Private property.
*
* @var string
*/
private string $private = 'private';
}
$foo = new ReflectionProperty('Foo', 'public');
var_dump($foo->getModifiers()); // int(17)
$foo = new ReflectionProperty('Foo', 'protected');
var_dump($foo->getModifiers()); // int(2)
$foo = new ReflectionProperty('Foo', 'private');
var_dump($foo->getModifiers()); // int(4)
ReflectionProperty::getName
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
var_dump($foo->getName()); // string(8) "property"
ReflectionProperty::getType
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
var_dump($foo->getType()); // object(ReflectionNamedType)#2 (0) { }
ReflectionProperty::getValue
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
var_dump($foo->getValue(new Foo())); // string(3) "foo"
ReflectionProperty::hasType
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $foo = 'foo';
/**
* Just a test property.
*
* @var string
*/
public $bar = 'bar';
}
$foo = new ReflectionProperty('Foo', 'foo');
var_dump($foo->hasType()); // bool(true)
$foo = new ReflectionProperty('Foo', 'bar');
var_dump($foo->hasType()); // bool(false)
ReflectionProperty::isDefault
<?php
class Foo
{
/**
* Just a test property.
*
* @var string|null
*/
public ?string $foo;
}
$foo = new ReflectionProperty('Foo', 'foo');
var_dump($foo->isDefault()); // bool(true)
ReflectionProperty::isInitialized
<?php
class Foo
{
/**
* Just a test property.
*
* @var string|null
*/
public ?string $foo;
/**
* Just a test property.
*
* @var string
*/
public string $bar = 'bar';
}
$foo = new ReflectionProperty('Foo', 'foo');
var_dump($foo->isInitialized(new Foo())); // bool(false)
$foo = new ReflectionProperty('Foo', 'bar');
var_dump($foo->isInitialized(new Foo())); // bool(true)
ReflectionProperty::isPrivate
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
private string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
var_dump($foo->isPrivate()); // bool(true)
ReflectionProperty::isProtected
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
protected string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
var_dump($foo->isProtected()); // bool(true)
ReflectionProperty::isPublic
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
var_dump($foo->isPublic()); // bool(true)
ReflectionProperty::isStatic
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public static string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
var_dump($foo->isStatic()); // bool(true)
ReflectionProperty::setAccessible
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
private string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
$foo->setAccessible(true);
var_dump($foo->getValue(new Foo())); // string(3) "foo"
ReflectionProperty::setValue
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $foo = 'foo';
/**
* Just a test property.
*
* @var string
*/
public static string $bar = 'bar';
}
$foo = new Foo();
$reflection = new ReflectionProperty('Foo', 'foo');
$reflection->setValue($foo, 'bar');
var_dump($foo->foo); // string(3) "bar"
$reflection = new ReflectionProperty('Foo', 'bar');
$reflection->setValue('foo');
var_dump(Foo::$bar); // string(3) "foo"
ReflectionProperty::__toString
<?php
class Foo
{
/**
* Just a test property.
*
* @var string
*/
public string $property = 'foo';
}
$foo = new ReflectionProperty('Foo', 'property');
echo $foo; // Property [ <default> public $property ]
print $foo; // Property [ <default> public $property ]
ReflectionType
ReflectionType::allowsNull
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->allowsNull()); // bool(false)
var_dump($foo->getType()->allowsNull()); // bool(false)
ReflectionType::isBuiltin
<?php
/**
* Just a test function.
*
* @param string $string
* @return void
*/
function foo(string $string)
{
//
}
/**
* Just a test function.
*
* @param Exception $exception
* @return void
*/
function bar(Exception $exception)
{
//
}
$foo = new ReflectionParameter('foo', 'string');
var_dump($foo->getType()->isBuiltin()); // bool(true)
$bar = new ReflectionParameter('bar', 'exception');
var_dump($bar->getType()->isBuiltin()); // bool(false)
ReflectionGenerator
ReflectionGenerator::__construct
<?php
/**
* Yielding test value.
*
* @param void
* @return void
*/
function foo()
{
yield 1;
}
var_dump(new ReflectionGenerator(foo())); // object(ReflectionGenerator)#1 (0) { }
ReflectionGenerator::getExecutingFile
<?php
/**
* Yielding test value.
*
* @param void
* @return void
*/
function foo()
{
yield 1;
}
$foo = new ReflectionGenerator(foo());
var_dump($foo->getExecutingFile());
ReflectionGenerator::getExecutingGenerator
<?php
/**
* Yielding test value.
*
* @param void
* @return void
*/
function foo()
{
yield 1;
}
$foo = new ReflectionGenerator(foo());
$foo = $foo->getExecutingGenerator();
var_dump($foo); // object(Generator)#2 (0) { }
foreach ($foo as $value) {
var_dump($value);
}
// int(1)
ReflectionGenerator::getExecutingLine
<?php
/**
* Yielding test value.
*
* @param void
* @return void
*/
function foo()
{
yield 1;
}
$foo = new ReflectionGenerator(foo());
var_dump($foo->getExecutingLine()); // int(11)
ReflectionGenerator::getFunction
<?php
/**
* Yielding test value.
*
* @param void
* @return void
*/
function foo()
{
yield 1;
}
$foo = new ReflectionGenerator(foo());
var_dump($foo->getFunction()); // object(ReflectionFunction)#3 (1) { ["name"]=> string(3) "foo" }
ReflectionGenerator::getThis
<?php
class Foo
{
/**
* Yielding test value.
*
* @param void
* @return void
*/
public function method()
{
yield 1;
}
}
$foo = new ReflectionGenerator((new Foo())->method());
var_dump($foo->getThis()); // object(Foo)#2 (0) { }
ReflectionGenerator::getTrace
<?php
/**
* Yielding test value.
*
* @param void
* @return void
*/
function foo()
{
yield 1;
}
/**
* Yielding test value.
*
* @param void
* @return void
*/
function bar()
{
yield from foo();
}
/**
* Yielding test value.
*
* @param void
* @return void
*/
function baz()
{
yield from bar();
}
$baz = baz();
$baz->valid();
$baz = new ReflectionGenerator($baz);
var_dump($baz->getTrace());