diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /tests/classes/property_recreate_private.phpt | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'tests/classes/property_recreate_private.phpt')
-rw-r--r-- | tests/classes/property_recreate_private.phpt | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/classes/property_recreate_private.phpt b/tests/classes/property_recreate_private.phpt new file mode 100644 index 0000000..8bcf485 --- /dev/null +++ b/tests/classes/property_recreate_private.phpt @@ -0,0 +1,81 @@ +--TEST-- +Unsetting and recreating private properties. +--FILE-- +<?php +class C { + private $p = 'test'; + function unsetPrivate() { + unset($this->p); + } + function setPrivate() { + $this->p = 'changed'; + } +} + +class D extends C { + function setP() { + $this->p = 'changed in D'; + } +} + +echo "Unset and recreate a superclass's private property:\n"; +$d = new D; +$d->unsetPrivate(); +$d->setPrivate(); +var_dump($d); + +echo "\nUnset superclass's private property, and recreate it as public in subclass:\n"; +$d = new D; +$d->unsetPrivate(); +$d->setP(); +var_dump($d); + +echo "\nUnset superclass's private property, and recreate it as public at global scope:\n"; +$d = new D; +$d->unsetPrivate(); +$d->p = 'this will create a public property'; +var_dump($d); + + +echo "\n\nUnset and recreate a private property:\n"; +$c = new C; +$c->unsetPrivate(); +$c->setPrivate(); +var_dump($c); + +echo "\nUnset a private property, and attempt to recreate at global scope (expecting failure):\n"; +$c = new C; +$c->unsetPrivate(); +$c->p = 'this will fail'; +var_dump($c); +?> +==Done== +--EXPECTF-- +Unset and recreate a superclass's private property: +object(D)#%d (1) { + [%u|b%"p":%u|b%"C":private]=> + %unicode|string%(7) "changed" +} + +Unset superclass's private property, and recreate it as public in subclass: +object(D)#%d (1) { + [%u|b%"p"]=> + %unicode|string%(12) "changed in D" +} + +Unset superclass's private property, and recreate it as public at global scope: +object(D)#%d (1) { + [%u|b%"p"]=> + %unicode|string%(34) "this will create a public property" +} + + +Unset and recreate a private property: +object(C)#%d (1) { + [%u|b%"p":%u|b%"C":private]=> + %unicode|string%(7) "changed" +} + +Unset a private property, and attempt to recreate at global scope (expecting failure): + +Fatal error: Cannot access private property C::$p in %s on line 46
\ No newline at end of file |