2008-12-06 06:12:04 +08:00
|
|
|
--TEST--
|
|
|
|
Unsetting and recreating protected properties.
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
class C {
|
|
|
|
protected $p = 'test';
|
|
|
|
function unsetProtected() {
|
2018-09-17 01:16:42 +08:00
|
|
|
unset($this->p);
|
2008-12-06 06:12:04 +08:00
|
|
|
}
|
|
|
|
function setProtected() {
|
2018-09-17 01:16:42 +08:00
|
|
|
$this->p = 'changed';
|
2008-12-06 06:12:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class D extends C {
|
|
|
|
function setP() {
|
|
|
|
$this->p = 'changed in D';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$d = new D;
|
|
|
|
echo "Unset and recreate a protected property from property's declaring class scope:\n";
|
|
|
|
$d->unsetProtected();
|
|
|
|
$d->setProtected();
|
|
|
|
var_dump($d);
|
|
|
|
|
|
|
|
echo "\nUnset and recreate a protected property from subclass:\n";
|
|
|
|
$d = new D;
|
|
|
|
$d->unsetProtected();
|
|
|
|
$d->setP();
|
|
|
|
var_dump($d);
|
|
|
|
|
|
|
|
echo "\nUnset a protected property, and attempt to recreate it outside of scope (expected failure):\n";
|
|
|
|
$d->unsetProtected();
|
|
|
|
$d->p = 'this will fail';
|
|
|
|
var_dump($d);
|
|
|
|
?>
|
|
|
|
--EXPECTF--
|
|
|
|
Unset and recreate a protected property from property's declaring class scope:
|
|
|
|
object(D)#%d (1) {
|
2016-11-23 05:12:07 +08:00
|
|
|
["p":protected]=>
|
|
|
|
string(7) "changed"
|
2008-12-06 06:12:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Unset and recreate a protected property from subclass:
|
|
|
|
object(D)#%d (1) {
|
2016-11-23 05:12:07 +08:00
|
|
|
["p":protected]=>
|
|
|
|
string(12) "changed in D"
|
2008-12-06 06:12:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Unset a protected property, and attempt to recreate it outside of scope (expected failure):
|
|
|
|
|
2015-05-18 06:31:43 +08:00
|
|
|
Fatal error: Uncaught Error: Cannot access protected property %s::$p in %s:32
|
2015-05-16 03:04:07 +08:00
|
|
|
Stack trace:
|
|
|
|
#0 {main}
|
|
|
|
thrown in %s on line 32
|