ID:               41929
 Comment by:       judas dot iscariote at gmail dot com
 Reported By:      robin at soal dot org
 Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: Windows
 PHP Version:      5CVS-2007-07-08 (snap)
 New Comment:

How do you understand  visibility ?

of course $priv is visible, but **in the context of class C** as you
defined it as "private" !!! (hint, hint)

$this in your code is(as expected) an instance of class D not of class
C ;-)

if you make $priv "protected" it will work as expected (hint,hint)


Previous Comments:
------------------------------------------------------------------------

[2007-07-08 20:03:41] robin at soal dot org

Description:
------------
The documentation states that "all visible properties will be used for
the iteration" when foreach'ing over an object.
Below is a case where this is not true.

Reproduce code:
---------------
<?php
class C {

  private $priv = "A private variable";

  function doLoop() {
    echo "Proof that the private is visible: " . $this->priv . "\n";
    foreach ($this as $k=>$v) {
      echo "The private is visible so should be accessed in the
loop:\n";
      echo "-> $k: $v";
    }
  }
  
}

class D extends C {}

$myD = new D;
$myD->doLoop();
?>

Expected result:
----------------
Proof that the private is visible: A private variable
The private is visible so should be accessed in the loop:
-> priv: A private variable

Actual result:
--------------
Proof that the private is visible: A private variable


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41929&edit=1

Reply via email to