#48355 [Opn->Bgs]: Direct access to protected properties and methods
| From: | johannes@php.net | Date: | Sun, 24 May 2009 18:10:37 +0000 |
| Subject: | #48355 [Opn->Bgs]: Direct access to protected properties and methods | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-137687@lists.php.net to get a copy of this message | ||
ID: 48355
Updated by: johannes@php.net
Reported By: gaj dot capuder at spletna-postaja dot com
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: Vista
PHP Version: 5.3.0RC2
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
.
Previous Comments:
------------------------------------------------------------------------
[2009-05-21 12:58:47] gaj dot capuder at spletna-postaja dot com
Description:
------------
When accessing object properties directly witin object's parent (the
one which object extends) the property acts as if it was public (no
error).
Similar thing happens with protected constructors where new instance of
a certain class can be created using "new" when the call is made inside
of an object which is the parent or which extends the same parent.
Reproduce code:
---------------
class A {
public function access()
{
$b = new B;
echo $b->property;
}
}
class B extends A {
protected $property = 'Should be protected';
}
class C extends A {
}
$c = new C;
$c->access();
$b = new B;
echo $b->property;
Expected result:
----------------
Fatal error: Cannot access protected property B::$property
Actual result:
--------------
Protection is broken
Fatal error: Cannot access protected property B::$property
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48355&edit=1