File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / classes / property_recreate_protected.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, 6 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 protected properties.
    3: --FILE--
    4: <?php
    5: class C {
    6: 	protected $p = 'test';
    7: 	function unsetProtected() {
    8: 		unset($this->p);		
    9: 	}
   10: 	function setProtected() {
   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: $d = new D;
   22: echo "Unset and recreate a protected property from property's declaring class scope:\n";
   23: $d->unsetProtected();
   24: $d->setProtected();
   25: var_dump($d);
   26: 
   27: echo "\nUnset and recreate a protected property from subclass:\n";
   28: $d = new D;
   29: $d->unsetProtected();
   30: $d->setP();
   31: var_dump($d);
   32: 
   33: echo "\nUnset a protected property, and attempt to recreate it outside of scope (expected failure):\n";
   34: $d->unsetProtected();
   35: $d->p = 'this will fail';
   36: var_dump($d);
   37: ?>
   38: --EXPECTF--
   39: Unset and recreate a protected property from property's declaring class scope:
   40: object(D)#%d (1) {
   41:   [%u|b%"p":protected]=>
   42:   %unicode|string%(7) "changed"
   43: }
   44: 
   45: Unset and recreate a protected property from subclass:
   46: object(D)#%d (1) {
   47:   [%u|b%"p":protected]=>
   48:   %unicode|string%(12) "changed in D"
   49: }
   50: 
   51: Unset a protected property, and attempt to recreate it outside of scope (expected failure):
   52: 
   53: Fatal error: Cannot access protected property %s::$p in %s on line 32

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