Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7154 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30667 invoked by uid 1010); 17 Jan 2004 16:17:33 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 30643 invoked from network); 17 Jan 2004 16:17:33 -0000 Received: from unknown (HELO stella.fastforwardnetwork.com) (209.51.153.50) by pb1.pair.com with SMTP; 17 Jan 2004 16:17:33 -0000 Received: (qmail 4177 invoked from network); 17 Jan 2004 17:22:17 -0000 Received: from pd95190cc.dip.t-dialin.net (HELO hristov.com) (217.81.144.204) by d.goto.bg with SMTP; 17 Jan 2004 17:22:17 -0000 Message-ID: <40095DC3.2020301@hristov.com> Date: Sat, 17 Jan 2004 17:07:31 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20031230 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Pierre-Alain Joye CC: internals@lists.php.net References: <4009585D.4050906@hristov.com> <20040117170548.478e6330.paj@pearfr.org> In-Reply-To: <20040117170548.478e6330.paj@pearfr.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Casting of objects to array exports private/protected data From: php@hristov.com (Andrey Hristov) Pierre-Alain Joye wrote: > On Sat, 17 Jan 2004 16:44:29 +0100 > Andrey Hristov wrote: > > >>IMO, when casting to array with (array) only the public-ly visible >>members should returned. > > > Dunno, E_STRICT (as you can access them without notice/warning without > this flag)? > > In the same manner: > error_reporting(E_STRICT); > class some { > public $pub = 1; > protected $prot = 2; > private $priv = 3; > > } > class any extends some { > public $pub1 = 1; > function dump() { > var_dump($this); > } > } > var_dump((array)new any()); > $a = new any; > $a->dump(); > > ?> > > a var_dump should dump protected props from the parent class as they are > visible. Note the "funny" thing is that var_dump() alone do not display > the public|protected props, whatever is the context call. IMHO, that > sounds not very consistent, but only imho... Yes, it does not. Use print_r() for dumping. print_r() uses internal zend function to dump the variable content while var_dump() is defined in ext/standard/var.c and knows nothing about protected and private functions (or at least it was that 2 months ago). print_r() has the expected behavior of dumping data, but casting to array and getting protected/private data is nasty. Andrey