|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesprint_r (last revision 2010-08-24 10:17 UTC by junior_xkr at hotmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-08-24 12:17 UTC] aharvey@php.net
-Status: Open
+Status: Bogus
[2010-08-24 12:17 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
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 )