PHP Doku:: Gets value - reflectionproperty.getvalue.html

Verlauf / Chronik / History: (2) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzVariablen- und typbezogene ErweiterungenReflectionThe ReflectionProperty classReflectionProperty::getValue

Ein Service von Reinhard Neidl - Webprogrammierung.

The ReflectionProperty class

<<ReflectionProperty::getName

ReflectionProperty::isDefault>>

ReflectionProperty::getValue

(PHP 5)

ReflectionProperty::getValueGets value

Beschreibung

public mixed ReflectionProperty::getValue ([ string $object ] )

Gets the properties value.

Warnung

Diese Funktion ist bis jetzt nicht dokumentiert. Es steht nur die Liste der Argumente zur Verfügung.

Parameter-Liste

object

The object being reflected.

Rückgabewerte

The current value of the property.

Siehe auch


2 BenutzerBeiträge:
- Beiträge aktualisieren...
sergiy dot sokolenko at gmail dot com
29.06.2010 0:48
To allow protected and private properties to be accessed, you should use
ReflectionProperty::setAccessible(bool $accessible):

<?php
/** Class Foo with protected and private members */
class Foo {
    protected
$bar = 'barrr!';
    private
$baz = 'bazzz!';
}

$reflFoo = new ReflectionClass('Foo');
$reflBar = $reflFoo->getProperty('bar');
$reflBaz = $reflFoo->getProperty('baz');

// Set private and protected members accessible for getValue/setValue
$reflBar->setAccessible(true);
$reflBaz->setAccessible(true);

$foo = new Foo();
echo
$reflBar->getValue($foo); // will output "barrr!"
echo $reflBaz->getValue($foo); // will output "bazzz!"

// You can also setValue
$reflBar->setValue($foo, "new value");
echo
$reflBar->getValue($foo); // will output "new value"
?>
tedivm at tedivm dot com
10.01.2010 6:33
Note this function does not return the value for everything, only public properties. Protected or private properties will result in a exception being thrown.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)