File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / classes / property_recreate_private.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:06 2012 UTC (12 years, 5 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

    1: --TEST--
    2: Unsetting and recreating private properties.
    3: --FILE--
    4: <?php
    5: class C {
    6: 	private $p = 'test';
    7: 	function unsetPrivate() {
    8: 		unset($this->p);		
    9: 	}
   10: 	function setPrivate() {
   11: 		$this->p = 'changed';		
   12: 	}
   13: }
   14: 
   15: class D extends C {
   16: 	function setP() {
   17: 		$this->p = 'changed in D';
   18: 	}
   19: }
   20: 
   21: echo "Unset and recreate a superclass's private property:\n";
   22: $d = new D;
   23: $d->unsetPrivate();
   24: $d->setPrivate();
   25: var_dump($d);
   26: 
   27: echo "\nUnset superclass's private property, and recreate it as public in subclass:\n";
   28: $d = new D;
   29: $d->unsetPrivate();
   30: $d->setP();
   31: var_dump($d);
   32: 
   33: echo "\nUnset superclass's private property, and recreate it as public at global scope:\n";
   34: $d = new D;
   35: $d->unsetPrivate();
   36: $d->p = 'this will create a public property';
   37: var_dump($d);
   38: 
   39: 
   40: echo "\n\nUnset and recreate a private property:\n";
   41: $c = new C;
   42: $c->unsetPrivate();
   43: $c->setPrivate();
   44: var_dump($c);
   45: 
   46: echo "\nUnset a private property, and attempt to recreate at global scope (expecting failure):\n";
   47: $c = new C;
   48: $c->unsetPrivate();
   49: $c->p = 'this will fail';
   50: var_dump($c);
   51: ?>
   52: ==Done==
   53: --EXPECTF--
   54: Unset and recreate a superclass's private property:
   55: object(D)#%d (1) {
   56:   [%u|b%"p":%u|b%"C":private]=>
   57:   %unicode|string%(7) "changed"
   58: }
   59: 
   60: Unset superclass's private property, and recreate it as public in subclass:
   61: object(D)#%d (1) {
   62:   [%u|b%"p"]=>
   63:   %unicode|string%(12) "changed in D"
   64: }
   65: 
   66: Unset superclass's private property, and recreate it as public at global scope:
   67: object(D)#%d (1) {
   68:   [%u|b%"p"]=>
   69:   %unicode|string%(34) "this will create a public property"
   70: }
   71: 
   72: 
   73: Unset and recreate a private property:
   74: object(C)#%d (1) {
   75:   [%u|b%"p":%u|b%"C":private]=>
   76:   %unicode|string%(7) "changed"
   77: }
   78: 
   79: Unset a private property, and attempt to recreate at global scope (expecting failure):
   80: 
   81: Fatal error: Cannot access private property C::$p in %s on line 46

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>