Ask a Question related to PHP Development, Design and Development.
-
forseti at oak dot rpg dot pl #1
#26350 [NEW]: Inherited methods can't access private methods
From: forseti at oak dot rpg dot pl
Operating system: Windows 98 SE
PHP version: 5.0.0b2 (beta2)
PHP Bug Type: Zend Engine 2 problem
Bug description: Inherited methods can't access private methods
Description:
------------
When a method is inherited from a base class it seems that it retains its
context. When it's called from derived class object, it turns out that
method cannot access private fields of it's own (derived class) object.
What's strange, the inherited method can access protected fields easily.
As if 'protected' opened access not only for derived classes but for base
classes too.
This is a key issue if one wants to code the accessor only once, in base
class so that any derived class could use it and provide read-only access
to any field.
Reproduce code:
---------------
<?php
class ParentClass {
protected $a = 'ParentClass<br>';
public function get($arg) {
return $this->$arg;
}
}
class ChildClass extends ParentClass{
protected $b = 'ChildClass - Protected<br>';
private $c = 'ChildClass - Private<br>';
}
$test = new ChildClass;
echo $test->get('a');
echo $test->get('c'); //fatal error
echo $test->get('b'); //strange - it's ok
?>
Expected result:
----------------
ParentClass
ChildClass - Protected
ChildClass - Private
Anyway, 'protected' field should be accessible only in derived classes and
where declared.
Actual result:
--------------
ParentClass
ChildClass - Protected
Fatal error: Cannot access private property childclass::$c
--
Edit bug report at [url]http://bugs.php.net/?id=26350&edit=1[/url]
--
Try a CVS snapshot (php4): [url]http://bugs.php.net/fix.php?id=26350&r=trysnapshot4[/url]
Try a CVS snapshot (php5): [url]http://bugs.php.net/fix.php?id=26350&r=trysnapshot5[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=26350&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=26350&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=26350&r=needtrace[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=26350&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=26350&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=26350&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=26350&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=26350&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=26350&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=26350&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=26350&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=26350&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=26350&r=gnused[/url]
Floating point limitations: [url]http://bugs.php.net/fix.php?id=26350&r=float[/url]
forseti at oak dot rpg dot pl Guest
-
Contextmenu Methods
Can somebody tell me how do I use the following methods in plug in code 1. AVContextMenuAdditionProc 2. AVAppRegisterForContextMenuAddition A... -
#40056 [NEW]: Member Overloading methods ignore access modifiers
From: bugs dot php dot net at andrewprendergast dot com Operating system: Linux Red Hat EL PHP version: 5.2.1RC2 PHP Bug Type: ... -
BeginInvoke Methods
This is probably going to be obvious to most of you, but I can't seem to figure out the answer. If I have a web service method that I want to call... -
Access a Class properties/methods from a .aspx file ?????
Hi I have written a class (Vb.net) which supposed to write out page title, img URLs and other stuff. I can access the class methods and... -
Aliased setter methods behave differently than other methods?
Here's another question... I am aliasing and redefining certain methods, determined at runtime. Normal methods work fine, but methods ending in '='...



Reply With Quote

