ReflectionClass::export()函数是PHP中的内置函数,如果参数设置为TRUE,则用于返回字符串,否则返回NULL。
用法:
string ReflectionClass::export( mixed $argument, bool $return = FALSE)
参数:该函数接受上述和以下描述的两个参数:
- $argument:它包含要导出的用户定义的类。
- $return:它是布尔值TRUE或FALSE。
返回值:如果参数设置为TRUE,则此函数以字符串形式返回,否则返回NULL。
以下示例程序旨在说明PHP中的ReflectionClass::export()函数:
示例1:
<?php
// Defining a user-defined class Company
class Company {
public $var1 = 'GeeksforGeeks';
public $var2 = 'GFG';
public function type() {
return 'Company';
}
}
// Calling the export function
$A = ReflectionClass::export('Company', $return = TRUE);
// Getting the returned value
var_dump($A);
?>
输出:
string(389) "Class [ class Company ] { @@ /home/cg/root/7286175/main.php 4-11 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [2] { Property [ public $var1 ] Property [ public $var2 ] } - Methods [1] { Method [ public method type ] { @@ /home/cg/root/7286175/main.php 8 - 10 } } } "
示例2:
<?php
// Calling the export function on inbuilt ReflectionClass
$A = ReflectionClass::export('ReflectionClass');
// Getting the returned value
var_dump($A);
?>
输出:
Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { - Constants [3] { Constant [ integer IS_IMPLICIT_ABSTRACT ] { 16 } Constant [ integer IS_EXPLICIT_ABSTRACT ] { 32 } Constant [ integer IS_FINAL ] { 4 } } - Static properties [0] { } - Static methods [1] { Method [ <internal:Reflection, prototype Reflector> static public method export ] { - Parameters [2] { Parameter #0 [ <required> $argument ] Parameter #1 [ <optional> $return ] } } } - Properties [1] { Property [ <default> public $name ] } - Methods [50] { Method [ <internal:Reflection> final private method __clone ] { - Parameters [0] { } } Method [ <internal:Reflection, ctor> public method __construct ] { - Parameters [1] { Parameter #0 [ <required> $argument ] } } Method [ <internal:Reflection, prototype Reflector> public method __toString ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getName ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isInternal ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isUserDefined ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isAnonymous ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isInstantiable ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isCloneable ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getFileName ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getStartLine ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getEndLine ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getDocComment ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getConstructor ] { - Parameters [0] { } } Method [ <internal:Reflection> public method hasMethod ] { - Parameters [1] { Parameter #0 [ <required> $name ] } } Method [ <internal:Reflection> public method getMethod ] { - Parameters [1] { Parameter #0 [ <required> $name ] } } Method [ <internal:Reflection> public method getMethods ] { - Parameters [1] { Parameter #0 [ <optional> $filter ] } } Method [ <internal:Reflection> public method hasProperty ] { - Parameters [1] { Parameter #0 [ <required> $name ] } } Method [ <internal:Reflection> public method getProperty ] { - Parameters [1] { Parameter #0 [ <required> $name ] } } Method [ <internal:Reflection> public method getProperties ] { - Parameters [1] { Parameter #0 [ <optional> $filter ] } } Method [ <internal:Reflection> public method hasConstant ] { - Parameters [1] { Parameter #0 [ <required> $name ] } } Method [ <internal:Reflection> public method getConstants ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getConstant ] { - Parameters [1] { Parameter #0 [ <required> $name ] } } Method [ <internal:Reflection> public method getInterfaces ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getInterfaceNames ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isInterface ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getTraits ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getTraitNames ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getTraitAliases ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isTrait ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isAbstract ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isFinal ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getModifiers ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isInstance ] { - Parameters [1] { Parameter #0 [ <required> $object ] } } Method [ <internal:Reflection> public method newInstance ] { - Parameters [1] { Parameter #0 [ <required> $args ] } } Method [ <internal:Reflection> public method newInstanceWithoutConstructor ] { - Parameters [0] { } } Method [ <internal:Reflection> public method newInstanceArgs ] { - Parameters [1] { Parameter #0 [ <optional> array $args ] } } Method [ <internal:Reflection> public method getParentClass ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isSubclassOf ] { - Parameters [1] { Parameter #0 [ <required> $class ] } } Method [ <internal:Reflection> public method getStaticProperties ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getStaticPropertyValue ] { - Parameters [2] { Parameter #0 [ <required> $name ] Parameter #1 [ <optional> $default ] } } Method [ <internal:Reflection> public method setStaticPropertyValue ] { - Parameters [2] { Parameter #0 [ <required> $name ] Parameter #1 [ <required> $value ] } } Method [ <internal:Reflection> public method getDefaultProperties ] { - Parameters [0] { } } Method [ <internal:Reflection> public method isIterateable ] { - Parameters [0] { } } Method [ <internal:Reflection> public method implementsInterface ] { - Parameters [1] { Parameter #0 [ <required> $interface ] } } Method [ <internal:Reflection> public method getExtension ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getExtensionName ] { - Parameters [0] { } } Method [ <internal:Reflection> public method inNamespace ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getNamespaceName ] { - Parameters [0] { } } Method [ <internal:Reflection> public method getShortName ] { - Parameters [0] { } } } } NULL
参考: https://secure.php.net/manual/en/reflectionclass.export.php
相关用法
- PHP ReflectionExtension export()用法及代码示例
- PHP ReflectionMethod export()用法及代码示例
- PHP ReflectionFunction export()用法及代码示例
- PHP ReflectionClass getEndLine()用法及代码示例
- PHP ReflectionClass getDocComment()用法及代码示例
- PHP ReflectionClass getExtension()用法及代码示例
- PHP ReflectionClass getConstants()用法及代码示例
- PHP ReflectionClass inNamespace()用法及代码示例
- PHP ReflectionClass getStartLine()用法及代码示例
- PHP ReflectionClass getProperty()用法及代码示例
- PHP ReflectionClass isSubclassOf()用法及代码示例
- PHP ReflectionClass hasConstant()用法及代码示例
- PHP ReflectionClass getProperties()用法及代码示例
- PHP ReflectionClass getParentClass()用法及代码示例
- PHP ReflectionClass isIterateable()用法及代码示例
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 PHP | ReflectionClass export() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。