Bug #66145 [Opn->Nab]: Protected variable is not able to be accessed on inherited class.
| From: | bwoebi@php.net | Date: | Fri, 22 Nov 2013 18:33:24 +0000 |
| Subject: | Bug #66145 [Opn->Nab]: Protected variable is not able to be accessed on inherited class. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182894@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66145&edit=1
ID: 66145
Updated by: bwoebi@php.net
Reported by: d dot shankarnarayana at gmail dot com
Summary: Protected variable is not able to be accessed on
inherited class.
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Windows
PHP Version: 5.5Git-2013-11-22 (snap)
Block user comment: N
Private report: N
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
When classes inherit properties, the type of the property (protected/public) remains unchanged.
You are actually iterating outside of the class, so protected values aren't displayed.
Previous Comments:
------------------------------------------------------------------------
[2013-11-22 13:49:34] d dot shankarnarayana at gmail dot com
Description:
------------
I found this problem while i was going through the Iterators concept.
The problem:
class NewClass is inheriting MyClass , so the protected variable $protected should be accessible in
the NewClass. But while printing out the results , the $protected variable is not shown in the
key-value combinations except for the public variables.
Test script:
---------------
<?php
class MyClass
{
public $var1 = 'value 1';
public $var2 = 'value 2';
public $var3 = 'value 3';
protected $protected = 'protected var';
private $private = 'private var';
function iterateVisible() {
echo "MyClass::iterateVisible:\n";
foreach($this as $key => $value) {
print "$key => $value\n";
}
}
}
class NewClass extends MyClass
{
}
$class = new NewClass();
foreach($class as $key => $value) {
print "$key => $value\n";
}
echo "\n"
Expected result:
----------------
var1 => value 1
var2 => value 2
var3 => value 3
protected => protected var
Actual result:
--------------
var1 => value 1
var2 => value 2
var3 => value 3
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66145&edit=1