Bug #66145 [NEW]: Protected variable is not able to be accessed on inherited class.

From: Date: Fri, 22 Nov 2013 13:49:35 +0000
Subject: Bug #66145 [NEW]: Protected variable is not able to be accessed on inherited class.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182887@lists.php.net to get a copy of this message
From:             d dot shankarnarayana at gmail dot com
Operating system: Windows
PHP version:      5.5Git-2013-11-22 (snap)
Package:          Class/Object related
Bug Type:         Bug
Bug description:Protected variable is not able to be accessed on inherited class.

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 bug report at https://bugs.php.net/bug.php?id=66145&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=66145&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=66145&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=66145&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=66145&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=66145&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=66145&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=66145&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=66145&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=66145&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=66145&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=66145&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=66145&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=66145&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66145&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=66145&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=66145&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=66145&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66145&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=66145&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=66145&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#182887) next »