本文整理汇总了PHP中ReflectionProperty::isDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionProperty::isDefault方法的具体用法?PHP ReflectionProperty::isDefault怎么用?PHP ReflectionProperty::isDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionProperty
的用法示例。
在下文中一共展示了ReflectionProperty::isDefault方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: defaultValue
public function defaultValue()
{
if ($this->property->isDefault()) {
$defaultProperties = $this->property->getDeclaringClass()->getDefaultProperties();
return $defaultProperties[$this->property->getName()];
}
return null;
}
示例2: isDefault
/**
* Returns whether the property is a default property defined in the class.
*
* A default property is defined in the class definition.
* A non-default property is an instance specific state.
* @return bool
*/
public function isDefault()
{
if ($this->reflectionSource instanceof ReflectionProperty) {
return $this->reflectionSource->isDefault();
} else {
return parent::isDefault();
}
}
示例3: reflectProperty
function reflectProperty($class, $property)
{
$propInfo = new ReflectionProperty($class, $property);
echo "**********************************\n";
echo "Reflecting on property {$class}::{$property}\n\n";
echo "isDefault():\n";
var_dump($propInfo->isDefault());
echo "\n**********************************\n";
}
示例4: reflectProperty
function reflectProperty($class, $property)
{
$propInfo = new ReflectionProperty($class, $property);
echo "**********************************\n";
echo "Reflecting on property {$class}::{$property}\n\n";
echo "isDefault():\n";
var_dump($propInfo->isDefault());
echo "getModifiers():\n";
var_dump($propInfo->getModifiers());
echo "getDeclaringClass():\n";
var_dump($propInfo->getDeclaringClass());
echo "getDocComment():\n";
var_dump($propInfo->getDocComment());
echo "\n**********************************\n";
}
示例5: scan
//.........这里部分代码省略.........
// process 'implements' keyword
do {
$tokens->next();
$root = $tokens->is(T_NS_SEPARATOR);
$parent = $this->_parseName($tokens);
if ($root) {
// extends from root namespace
$class->addInterface($parent);
} elseif (isset($aliases[$parent])) {
$class->addInterface($aliases[$parent]);
} else {
$class->addInterface($_ns . $parent);
}
} while ($tokens->is(','));
}
$tokens->forwardTo('{')->next();
while ($tokens->forwardTo(T_CONST, T_FUNCTION, '{', '}', T_VARIABLE) && $tokens->valid()) {
switch ($tokens->key()) {
case T_CONST:
$constant = new EntityConstant($class->name . '::' . $tokens->next()->get(T_STRING));
$constant->setValue(constant($constant->name));
$constant->setLine(new Line($this, $tokens->getLine()));
$class->addConstant($constant);
break;
case T_VARIABLE:
$property = new EntityProperty(ltrim($tokens->getAndNext(), '$'));
$ref = new \ReflectionProperty($class->name, $property->name);
$doc = $ref->getDocComment();
if ($doc) {
$property->setDescription(ToolKit::parseDoc($doc)['desc']);
}
if ($ref->isPrivate()) {
$property->addFlag(Flags::IS_PRIVATE);
} elseif ($ref->isProtected()) {
$property->addFlag(Flags::IS_PROTECTED);
} else {
$property->addFlag(Flags::IS_PUBLIC);
}
if ($ref->isStatic()) {
$property->addFlag(Flags::IS_STATIC);
}
if ($ref->isDefault()) {
$property->setValue($ref->getDeclaringClass()->getDefaultProperties()[$property->name]);
}
$class->addProperty($property);
break;
case T_FUNCTION:
$method = new EntityMethod($name . '::' . $tokens->next()->get(T_STRING));
$method->setLine($this->line($tokens->getLine()));
$this->parseCallable($method, $ref = new \ReflectionMethod($class->name, $method->short));
if ($ref->isPrivate()) {
$method->addFlag(Flags::IS_PRIVATE);
} elseif ($ref->isProtected()) {
$method->addFlag(Flags::IS_PROTECTED);
} else {
$method->addFlag(Flags::IS_PUBLIC);
}
if ($ref->isStatic()) {
$method->addFlag(Flags::IS_STATIC);
}
if ($ref->isAbstract()) {
$method->addFlag(Flags::IS_ABSTRACT);
$method->addFlag(Flags::IS_ABSTRACT_IMPLICIT);
} elseif ($ref->isFinal()) {
$method->addFlag(Flags::IS_FINAL);
}
if (isset($method->options['deprecated'])) {
$method->addFlag(Flags::IS_DEPRECATED);
}
$tokens->forwardTo(')')->next();
if ($tokens->is('{')) {
$method_body = $tokens->getScope();
$method->setBody($method_body);
}
$tokens->next();
$class->addMethod($method);
break;
case '{':
// use traits scope
$tokens->forwardTo('}')->next();
break;
case '}':
// end of class
$tokens->next();
$this->classes[$class->name] = $class;
break 2;
}
}
} elseif ($tokens->is('}') && $ns_bracket) {
$tokens->next();
$ns_bracket = false;
} else {
drop($tokens->curr);
if ($tokens->valid()) {
throw new UnexpectedTokenException($tokens);
}
break;
}
}
}
示例6: A
<?php
class A
{
public $defprop;
}
$a = new A();
$a->myprop = null;
$ro = new ReflectionObject($a);
$props = $ro->getProperties();
$prop1 = $props[0];
var_dump($prop1->isDefault());
$prop2 = $props[1];
var_dump($prop2->isDefault());
var_dump($ro->getProperty('defprop')->isDefault());
var_dump($ro->getProperty('myprop')->isDefault());
$prop1 = new ReflectionProperty($a, 'defprop');
$prop2 = new ReflectionProperty($a, 'myprop');
var_dump($prop1->isDefault());
var_dump($prop2->isDefault());
?>
==DONE==
示例7: testSetUndefinedProperty
public function testSetUndefinedProperty()
{
$ins = $this->Basic::newWithoutConstructor();
$ins->undefined = 'newValue';
$this->assertEquals('newValue', $ins->undefined);
(function ($tester) {
$rp = new \ReflectionProperty($this->ins, 'undefined');
$tester->assertFalse($rp->isDefault());
})->call($ins, $this);
}
示例8: ReflectionProperty
<?php
class C
{
public static $p;
}
var_dump(new ReflectionProperty());
var_dump(new ReflectionProperty('C::p'));
var_dump(new ReflectionProperty('C', 'p', 'x'));
$rp = new ReflectionProperty('C', 'p');
var_dump($rp->getName(1));
var_dump($rp->isPrivate(1));
var_dump($rp->isProtected(1));
var_dump($rp->isPublic(1));
var_dump($rp->isStatic(1));
var_dump($rp->getModifiers(1));
var_dump($rp->isDefault(1));
示例9: ReflectionProperty
<pre>
<?php
class String
{
public $length = 5;
}
// Создание экземпляра класса ReflectionProperty
$prop = new ReflectionProperty('String', 'length');
// Вывод основной информации о свойстве класса
printf("===> %s%s%s%s свойство '%s' (которое было %s)\n" . " имеет модификаторы %s\n", $prop->isPublic() ? ' public' : '', $prop->isPrivate() ? ' private' : '', $prop->isProtected() ? ' protected' : '', $prop->isStatic() ? ' static' : '', $prop->getName(), $prop->isDefault() ? 'объявлено во время компиляции' : 'создано во время выполнения', var_export(Reflection::getModifierNames($prop->getModifiers()), 1));
exit;
// Создание экземпляра String
$obj = new String();
// Получение текущего значения
printf("---> Значение: ");
var_dump($prop->getValue($obj));
// Изменение значения
$prop->setValue($obj, 10);
printf("---> Установка значения 10, новое значение равно: ");
var_dump($prop->getValue($obj));
// Дамп объекта
var_dump($obj);
?>
</pre>
示例10: accessLengthProp
<?php
class String
{
public $length = 5;
function accessLengthProp(string $obj, $length)
{
$reflection = new ReflectionClass($obj);
$property = $reflection->getProperty($length);
$property->setAccessible(true);
return $property->getValue($obj);
}
}
$prop = new ReflectionProperty('String', 'length');
printf("<br/>===> The%s%s%s%s property '%s' (which was %s) having the modifiers %s<br/>", $prop->isPublic() ? ' public' : '', $prop->isPrivate() ? ' private' : '', $prop->isProtected() ? ' protected' : '', $prop->isStatic() ? ' static' : '', $prop->getName(), $prop->isDefault() ? 'declared at compile-time' : 'created at run-time', var_export(Reflection::getModifierNames($prop->getModifiers()), 1));
$obj = new String();
echo "<br/>===> The length property of the object is " . $obj->accessLengthProp($obj, 'length') . "<br/>";
printf("<br/>===> The value is: ");
echo $prop->getValue($obj) . "<br/>";
$prop->setValue($obj, 10);
printf("<br/>===> The setting value to 10, new value is: ");
echo " " . $prop->getValue($obj);
/* output
===> The public property 'length' (which was declared at compile-time) having the modifiers array ( 0 => 'public', )
===> The length property of the object is 5
===> The value is: 5
===> The setting value to 10, new value is: 10
示例11: cloneSchema
/**
* Clone parameter options using ReflectionProperty.
*
* @param \ReflectionProperty $property
*/
public function cloneSchema(\ReflectionProperty $property)
{
$this->setDefault(false);
$this->setComment($property->getDocComment());
$this->static = $property->isStatic();
if ($property->isPrivate()) {
$this->setAccess(self::ACCESS_PRIVATE);
} elseif ($property->isProtected()) {
$this->setAccess(self::ACCESS_PROTECTED);
}
if (!$property->isDefault()) {
return;
}
$parentDefaults = $property->getDeclaringClass()->getDefaultProperties();
foreach ($parentDefaults as $name => $defaultValue) {
if ($name == $property->getName()) {
$this->setDefault(true, $defaultValue);
break;
}
}
}