|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-10-20 10:30 UTC] stochnagara at hotmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 17:00:01 2025 UTC |
Description: ------------ i'm often making heavy use of the decorator pattern. while this works in c++ or java, php tells me the 'protected' context does not work. how's this to interpret? Reproduce code: --------------- <?php abstract class A { protected abstract function func(); } class Decorator extends A { private $_decorated; public function __construct(A $a) { $this -> _decorated = $a; } protected function func() { $this -> _decorated -> func(); } public function doCall() { $this -> func(); } } class ASmall extends A { protected function func() { printf("%s::%s called!\n",__CLASS__,__FUNCTION__); } } $a = new ASmall(); $dec = new Decorator($a); $dec -> doCall(); die(); Expected result: ---------------- ASmall::func called! Actual result: -------------- <br /> <b>Fatal error</b>: Call to protected method ASmall::func() from context 'Decorator' in <b>fileName</b> on line <b>12</b><br />