ID:               36693
 Comment by:       nacho at ziggo dot nl
 Reported By:      iain at iaindooley dot com
 Status:           No Feedback
 Bug Type:         Class/Object related
 Operating System: FreeBSD 6.0
 PHP Version:      5.1.2
 New Comment:

Correction (I was actually testing on another machine where 5.1 is
running). Actual output on 5.3.1 is:

array(3) {
  ["a"]=>
  string(1) "a"
  ["b"]=>
  string(1) "b"
  ["c"]=>
  string(1) "c"
}
array(5) {
  ["e"]=>
  string(1) "e"
  ["f"]=>
  string(1) "f"
  ["a"]=>
  string(1) "a"
  ["b"]=>
  string(1) "b"
  ["c"]=>
  string(1) "c"
}

While "a" should indeed not have to be visible to "Bar", as it is a
private property of "Foo", like the output of version 5.1 show, on 5.3.1
it seems as it is interchanged with the private property "d" of "Bar",
which should be visible to itself ("Bar").


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

[2010-02-22 15:04:09] nacho at ziggo dot nl

Description:
------------
This seems to be broken again on version 5.3.1 (Debian/Apache)

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

        private $a = 'a';

        public $b = 'b';

        protected $c = 'c';

        public function __construct() {}

        public function Export() {

                $vars = get_object_vars($this);

                return $vars;

        }

}

class Bar extends Foo {

        private $d = 'd';

        public $e = 'e';

        protected $f = 'f';

}

$foo = new Foo();
$bar = new Bar();

var_dump($foo->Export());
var_dump($bar->Export());
?>

Expected result:
----------------
array(3) {
  ["a"]=>
  string(1) "a"
  ["b"]=>
  string(1) "b"
  ["c"]=>
  string(1) "c"
}
array(5) {
  ["d"]=>
  string(1) "d"
  ["e"]=>
  string(1) "e"
  ["f"]=>
  string(1) "f"
  ["a"]=>
  string(1) "a"
  ["b"]=>
  string(1) "b"
  ["c"]=>
  string(1) "c"
}

Actual result:
--------------
array(3) {
  ["a"]=>
  string(1) "a"
  ["b"]=>
  string(1) "b"
  ["c"]=>
  string(1) "c"
}
array(5) {
  ["d"]=>
  string(1) "d"
  ["e"]=>
  string(1) "e"
  ["f"]=>
  string(1) "f"
  ["b"]=>
  string(1) "b"
  ["c"]=>
  string(1) "c"
}

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

[2006-08-16 21:13:52] tony2...@php.net

That's correct behavior, since you're calling it outside of the object
scope.

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

[2006-08-16 20:50:09] thomas at epiphantastic dot com

Forgot to say, I'm running PHP 5.1.2

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

[2006-08-16 20:48:52] thomas at epiphantastic dot com

I'm experiencing this same problem, running PHP on Windows with both
Apache and IIS. Here's the code:

<?php
class TestClass {
        private $var1 = "private";
        protected $var2 = "protected";
        public $var3 = "public";
}

$o = new TestClass();
foreach(array_keys(get_object_vars($o)) as $key)
        echo $key;
?>

I'd expect to see 3 values outputted but only one comes back.

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

[2006-03-23 01:00:05] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/36693

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

Reply via email to