ID:               45862
 Updated by:       [EMAIL PROTECTED]
 Reported By:      ilewis at uk dot ibm dot com
-Status:           Verified
+Status:           Assigned
 Bug Type:         Class/Object related
 Operating System: fedora 8
 PHP Version:      5.2CVS, 5.3CVS, 6CVS
-Assigned To:      
+Assigned To:      felipe


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

[2008-08-19 10:27:05] ilewis at uk dot ibm dot com

Description:
------------
get_class_vars() sometimes returns protected and private variables,
depending on the calling scope. However, the behaviour is inconsistent
with the visibility of the variables. Private variables are found when
calling from child scope (they aren't visible), and protected variables
are _not_ found from parent scope (they are visible).

It feels as though get_class_vars() should respect visibility entirely
or not at all

The expected output below is what would be produced if get_class_vars
respected visibility consistently. I've put a patch (built against snap
php5.3-200808180830) that produces this behaviour on pastebin:
http://pastebin.com/m10403f42

I used the old logic from property_exists() for the patch (although
that has now been changed so that property_exists no longer respects
visibility)

Reproduce code:
---------------
<?php
class Ancestor {
  function test() {
    var_dump(get_class_vars("Tester"));
    var_dump(Tester::$prot);
  }
}

class Tester extends Ancestor {
  static protected $prot = "protected var";
  static private $priv = "private var";
}

class Child extends Tester {
  function test() { var_dump(get_class_vars("Tester")); }
}

echo "\n From parent scope\n";
$parent = new Ancestor();
$parent->test();
echo "\n From child scope\n";
$child = new Child();
$child->test();
?>


Expected result:
----------------
 From parent scope
array(1) {
  ["prot"]=>
  string(13) "protected var"
}
string(13) "protected var"

 From child scope
array(1) {
  ["prot"]=>
  string(13) "protected var"
}


Actual result:
--------------
 From parent scope
array(0) {
}
string(13) "protected var"

 From child scope
array(2) {
  ["prot"]=>
  string(13) "protected var"
  ["priv"]=>
  string(11) "private var"
}



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


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

Reply via email to