mirror of
https://github.com/php/php-src.git
synced 2024-11-24 02:15:04 +08:00
c9f27ee422
TypeException stays as-is for now because it uses messages that are incompatible with the way exception messages are displayed. closure_038.phpt and a few others now show that we're generating too many exceptions for compound operations on undefined properties -- this needs to be fixed in a followup.
57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
--TEST--
|
|
Unsetting and recreating protected properties.
|
|
--FILE--
|
|
<?php
|
|
class C {
|
|
protected $p = 'test';
|
|
function unsetProtected() {
|
|
unset($this->p);
|
|
}
|
|
function setProtected() {
|
|
$this->p = 'changed';
|
|
}
|
|
}
|
|
|
|
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) {
|
|
[%u|b%"p":protected]=>
|
|
%unicode|string%(7) "changed"
|
|
}
|
|
|
|
Unset and recreate a protected property from subclass:
|
|
object(D)#%d (1) {
|
|
[%u|b%"p":protected]=>
|
|
%unicode|string%(12) "changed in D"
|
|
}
|
|
|
|
Unset a protected property, and attempt to recreate it outside of scope (expected failure):
|
|
|
|
Fatal error: Uncaught exception 'EngineException' with message 'Cannot access protected property %s::$p' in %s:32
|
|
Stack trace:
|
|
#0 {main}
|
|
thrown in %s on line 32
|