[PATCH] Re: Bug#27798 protected/private access and get_object_vars()

From: Date: Tue, 18 May 2004 20:00:05 +0000
Subject: [PATCH] Re: Bug#27798 protected/private access and get_object_vars()
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-9946@lists.php.net to get a copy of this message
> > The next question that brings up then is in relation to bug#27798: > > > > I would think that get_object_vars() should expose private/protected props > > when called from within the class itself (as appropriate based on > > inheretance of course). Is this assumption true? > > yeah, I think that's how it should work. > Then how does this patch look: http://frankenbox.alphaweb.net/test/27798.diff With the following script: class A { public $a = 'A'; protected $b = 'B'; private $c = 'C'; function look_from_a() { echo "From A: "; var_dump( get_object_vars($this) ); } } class B extends A { function look_from_b() { echo "From B: "; var_dump( get_object_vars($this) ); } } $b = new B(); $b->look_from_a(); $b->look_from_b(); echo "From outside the objects: "; var_dump(get_object_vars($b)); It displays: From A: array(3) { ["a"]=> string(1) "A" ["b"]=> string(1) "B" ["c"]=> string(1) "C" } From B: array(2) { ["a"]=> string(1) "A" ["b"]=> string(1) "B" } From outside the objects: array(1) { ["a"]=> string(1) "A" } Everyone happy with that behavior? -Sara

« previous php.internals (#9946) next »