php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34924 Decorator pattern - php implementation
Submitted: 2005-10-20 02:22 UTC Modified: 2005-10-20 20:51 UTC
Votes:3
Avg. Score:3.7 ± 1.9
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: axo at axolander dot de Assigned: dmitry (profile)
Status: Wont fix Package: Class/Object related
PHP Version: 5.0.5 OS: UNIX
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: axo at axolander dot de
New email:
PHP Version: OS:

 

 [2005-10-20 02:22 UTC] axo at axolander dot de
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 />

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-20 10:30 UTC] stochnagara at hotmail dot com
This bug is also present in latest 5.1 snap.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jan 05 05:01:28 2025 UTC