|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-11-22 18:33 UTC] bwoebi@php.net
-Status: Open
+Status: Not a bug
[2013-11-22 18:33 UTC] bwoebi@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 18 22:00:01 2025 UTC |
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