2008-02-15 12:38:53 +00:00
|
|
|
--TEST--
|
2008-02-15 12:48:13 +00:00
|
|
|
Test ReflectionProperty::setAccessible().
|
2008-02-15 12:38:53 +00:00
|
|
|
--SKIPIF--
|
|
|
|
<?php extension_loaded('reflection') or die('skip'); ?>
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
|
|
|
|
class TestClass {
|
|
|
|
public $pub;
|
|
|
|
public $pub2 = 5;
|
|
|
|
static public $stat = "static property";
|
|
|
|
protected $prot = 4;
|
|
|
|
private $priv = "keepOut";
|
|
|
|
}
|
|
|
|
|
|
|
|
class AnotherClass {
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance = new TestClass();
|
|
|
|
|
|
|
|
echo "\nProtected property:\n";
|
|
|
|
$propInfo = new ReflectionProperty('TestClass', 'prot');
|
|
|
|
try {
|
|
|
|
var_dump($propInfo->getValue($instance));
|
|
|
|
}
|
|
|
|
catch(Exception $exc) {
|
|
|
|
echo $exc->getMessage(), "\n";
|
|
|
|
}
|
|
|
|
|
2008-02-15 12:48:13 +00:00
|
|
|
$propInfo->setAccessible(true);
|
2008-02-15 12:38:53 +00:00
|
|
|
var_dump($propInfo->getValue($instance));
|
|
|
|
|
2008-02-15 12:48:13 +00:00
|
|
|
$propInfo->setAccessible(false);
|
2008-02-15 12:38:53 +00:00
|
|
|
try {
|
|
|
|
var_dump($propInfo->getValue($instance));
|
|
|
|
}
|
|
|
|
catch(Exception $exc) {
|
|
|
|
echo $exc->getMessage(), "\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
--EXPECTF--
|
|
|
|
|
|
|
|
Protected property:
|
|
|
|
Cannot access non-public member TestClass::prot
|
|
|
|
int(4)
|
|
|
|
Cannot access non-public member TestClass::prot
|