本文整理汇总了PHP中ReflectionProperty::export方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionProperty::export方法的具体用法?PHP ReflectionProperty::export怎么用?PHP ReflectionProperty::export使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionProperty
的用法示例。
在下文中一共展示了ReflectionProperty::export方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reflectProperty
function reflectProperty($class, $property)
{
$propInfo = new ReflectionProperty($class, $property);
echo "**********************************\n";
echo "Reflecting on property {$class}::{$property}\n\n";
echo "__toString():\n";
var_dump($propInfo->__toString());
echo "export():\n";
var_dump(ReflectionProperty::export($class, $property, true));
echo "export():\n";
var_dump(ReflectionProperty::export($class, $property, false));
echo "getName():\n";
var_dump($propInfo->getName());
echo "isPublic():\n";
var_dump($propInfo->isPublic());
echo "isPrivate():\n";
var_dump($propInfo->isPrivate());
echo "isProtected():\n";
var_dump($propInfo->isProtected());
echo "isStatic():\n";
var_dump($propInfo->isStatic());
$instance = new $class();
if ($propInfo->isPublic()) {
echo "getValue():\n";
var_dump($propInfo->getValue($instance));
$propInfo->setValue($instance, "NewValue");
echo "getValue() after a setValue():\n";
var_dump($propInfo->getValue($instance));
}
echo "\n**********************************\n";
}
示例2: catch
<?php
class TestClass
{
}
$a = 5;
echo "Non-existent class:\n";
try {
ReflectionProperty::export("NonExistentClass", "prop", true);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\n\nWrong property parameter type:\n";
try {
ReflectionProperty::export($a, 'TestClass', false);
} catch (ReflectionException $e) {
echo $e->getMessage();
}
echo "\n\nNon-existent property:\n";
try {
ReflectionProperty::export('TestClass', "nonExistentProperty", true);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\n\nIncorrect number of args:\n";
ReflectionProperty::export();
ReflectionProperty::export('TestClass', "nonExistentProperty", true, false);
示例3: Func
<?php
class Foo
{
public $prop;
function Func($name)
{
echo "Hello {$name}";
}
}
ReflectionClass::export('Foo');
//output: Class [ class Foo ] { @@ /home/cg/root/main.php 3-10 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [1] { Property [ public $prop ] } - Methods [1] { Method [ public method Func ] { @@ /home/cg/root/main.php 7 - 9 - Parameters [1] { Parameter #0 [ $name ] } } } }
ReflectionObject::export(new Foo());
// output: Object of class [ class Foo ] { @@ /home/cg/root/main.php 3-10 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [1] { Property [ public $prop ] } - Dynamic properties [0] { } - Methods [1] { Method [ public method Func ] { @@ /home/cg/root/main.php 7 - 9 - Parameters [1] { Parameter #0 [ $name ] } } } }
ReflectionMethod::export('Foo', 'func');
// output: Method [ public method Func ] { @@ /home/cg/root/main.php 7 - 9 - Parameters [1] { Parameter #0 [ $name ] } }
ReflectionProperty::export('Foo', 'prop');
//output: Property [ public $prop ]
ReflectionExtension::export('standard');
//output: Extension [ extension #15 standard version 5.5.18 ] ...
示例4: testToString
/**
* Tests export.
*/
public function testToString()
{
$tests = array('lines', 'docComment', 'noComment', 'default', 'typeNull', 'typeArray', 'typeString', 'typeInteger', 'typeFloat');
foreach ($tests as $test) {
$rfl = $this->getPropertyReflection($test);
$this->assertSame($rfl->internal->__toString(), $rfl->token->__toString());
$this->assertSame(InternalReflectionProperty::export($this->getClassName($test), $test, true), ReflectionProperty::export($this->getBroker(), $this->getClassName($test), $test, true));
// Test loading from a string
$rfl = $this->getPropertyReflection($test, true);
$this->assertSame($rfl->internal->__toString(), $rfl->token->__toString());
}
$rfl = $this->getClassReflection('modifiers');
$rfl_fromString = $this->getClassReflection('modifiers');
foreach (array('public', 'protected', 'private') as $name) {
$internal = $rfl->internal->getProperty($name);
$token = $rfl->token->getProperty($name);
$this->assertSame($internal->__toString(), $token->__toString());
$this->assertSame(InternalReflectionProperty::export($this->getClassName('modifiers'), $name, true), ReflectionProperty::export($this->getBroker(), $this->getClassName('modifiers'), $name, true));
// Test loading from a string
$this->assertSame($internal->__toString(), $rfl_fromString->token->getProperty($name)->__toString());
}
$this->assertSame(InternalReflectionProperty::export('ReflectionProperty', 'name', true), ReflectionProperty::export($this->getBroker(), 'ReflectionProperty', 'name', true));
$this->assertSame(InternalReflectionProperty::export(new InternalReflectionProperty('ReflectionProperty', 'name'), 'name', true), ReflectionProperty::export($this->getBroker(), new InternalReflectionProperty('ReflectionProperty', 'name'), 'name', true));
}
示例5: var_dump
<?php
class TestClass
{
public $proper = 5;
}
var_dump(ReflectionProperty::export('TestClass', 'proper'));
示例6: export
/**
* Exports a ReflectionProperty instance.
*
* Returns the output if TRUE is specified for return, printing it otherwise.
* This is purely a wrapper method, which calls the corresponding method of
* the parent class.
* @param ReflectionClass|string $class
* ReflectionClass object or name of the class
* @param ReflectionProperty|string $property
* ReflectionProperty object or name of the class
* @param boolean $return
* Whether to return (TRUE) or print (FALSE) the output
* @return mixed
*/
public static function export($class, $property, $return = false)
{
return parent::export($class, $property, $return);
}