note 83078 added to function.get-object-vars

From: Date: Thu, 08 May 2008 23:38:47 +0000
Subject: note 83078 added to function.get-object-vars
Groups: php.notes 
Request: Send a blank email to php-notes+get-139197@lists.php.net to get a copy of this message
get_object_vars() has confusing behaviour when called as get_object_vars($this) or similar: since a method inside a class definition can access private vars, apparently so can get_object_vars(), so it returns private vars as well. A simple workaround is to define a method that in itself calls get_object_vars, like: <?php function getPublicObjectVars($obj) { return get_object_vars($obj); } class Smth { private $notShown = 1; public $shown = 2; function test() { $vars = get_object_vars($this); // includes 'notShown' $vars = getPublicObjectVars($this); // only 'shown' } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 201.83.88.237 ---- Manual Page -- http://www.php.net/manual/en/function.get-object-vars.php Edit -- https://master.php.net/note/edit/83078 Del: integrated -- https://master.php.net/note/delete/83078/integrated Del: useless -- https://master.php.net/note/delete/83078/useless Del: bad code -- https://master.php.net/note/delete/83078/bad+code Del: spam -- https://master.php.net/note/delete/83078/spam Del: non-english -- https://master.php.net/note/delete/83078/non-english Del: in docs -- https://master.php.net/note/delete/83078/in+docs Del: other reasons-- https://master.php.net/note/delete/83078 Reject -- https://master.php.net/note/reject/83078 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139197) next »