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