From: Operating system: Windows PHP version: Irrelevant Package: Class/Object related Bug Type: Bug Bug description:Getting value from private/protected atribute.
Description: ------------ Using the function print_r(), you can view content of an class attribute: class Object ( [attribute:private] => value [fvox:protected] => synyster ) But, if you try to access outside of class, the script will throw an exception: $fx = new fvox; echo $fx->synyster; Result: Fatal error: Cannot access private property class::$fvox in ... I don't know if it's really a bug, but i think it isn't safe. Test script: --------------- <? class fvox { private $synyster = 'invaders'; protected $fx = 'junior'; } function getVars($class){ eval('$of = new '.$class); ob_start(); print_r($of); $buf = ob_get_contents(); ob_end_clean(); preg_match_all('/\[([^:]+):(private|protected)]/i', $buf, $vars); preg_match_all('/=> (.+)/i', $buf, $values); $r = array(); for($i=0;$i<count($vars[1]);$i++) $r[$vars[1][$i]] = $values[1][$i]; return $r; } print_r(getVars('fvox();')); ?> Expected result: ---------------- Array ( ) Actual result: -------------- Array ( [synyster] => invaders [fx] => junior ) -- Edit bug report at http://bugs.php.net/bug.php?id=52685&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52685&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52685&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52685&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52685&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52685&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52685&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52685&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52685&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52685&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52685&r=support Expected behavior: http://bugs.php.net/fix.php?id=52685&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52685&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52685&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52685&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52685&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52685&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52685&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52685&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52685&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52685&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52685&r=mysqlcfg