From:             ilewis at uk dot ibm dot com
Operating system: fedora 8
PHP version:      5.3.0alpha1
PHP Bug Type:     Reflection related
Bug description:  get_class_vars is inconsistent with 'protected' and 'private' 
variables

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

Reply via email to