Possible bug in get_class_vars() - Fwd: Re: [PHP-NOTES] note 9782 added to get_class_vars
| From: | J. M. Castagnetto | Date: | Mon, 27 Nov 2000 10:48:58 +0000 |
| Subject: | Possible bug in get_class_vars() - Fwd: Re: [PHP-NOTES] note 9782 added to get_class_vars | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-39218@lists.php.net to get a copy of this message | ||
Problem with the beahviour of get_class_vars() in
declared by uninstantiated classes, description below.
--- Albert Xin Jiang <albertjiang@yahoo.com> wrote:
> Date: Sat, 25 Nov 2000 04:07:33 -0800 (PST)
> From: Albert Xin Jiang <albertjiang@yahoo.com>
> Subject: Re: [PHP-NOTES] note 9782 added to
> get_class_vars
> To: "J. M. Castagnetto" <jcastagnetto@yahoo.com>,
> php-notes@lists.php.net
>
> Thanks for the reply!
> I went back and tested it again, and this is what I
> found out:
>
> get_class_vars() only works as expected IF the class
> has been instantiated before. In your example,
> without the
> $o = new $foo();
> statement, print_r($vars) would fail silently,
> while var_dump($vars) would output something like
>
> array(5)
> {
>
> ["name"] => string(10) "foo object"
>
> ["boolarr"] => UNKNOWN:0
>
> }
>
> Another interesting example: suppose class b is a
> subclass of a, and we
> instantiate class b, then get_class_vars('b')
> would
> work fine, with all
> the inherited member variables. But
> get_class_vars('a') would still choke
> on arrays.
>
> Is this the expected behavior? In my particular
> situation, I want to access
> a member variable $defaults['img_width'] outside of
> the class,
> divide it by say 5, and pass the result to the
> constructor.
> It's no use to change it after the instantiation,
> because the constructor uses it to do other things.
> There are probably ways to work around this, but I
> thought get_class_vars()
> is designed to solve these kind of problems....
>
> Cheers,
> Albert
>
>
> --- "J. M. Castagnetto" <jcastagnetto@yahoo.com>
> wrote:
> > Incorrect. The following works as expected (PHP
> > 4.0.3pl1, RH 6.1):
> >
> > class foo {
> > var $boolarr = array("false"=>0, "true"=>1);
> > var $name = "foo object";
> >
> > function foo ($name="") {
> > if ($name)
> > $this->name = $name;
> > }
> > }
> >
> > $o = new foo();
> > $vars = get_class_vars("foo");
> > print_r($vars);
> >
> > Outputs:
> >
> > Array
> > (
> > [boolarr] => Array
> > (
> > [false] => 0
> > [true] => 1
> > )
> >
> > [name] => foo object
> > )
> >
> >
> > Your code logic may be incorrect. Are you testing
> to
> > see what type of result each array item has?
> >
> > Your note will be removed.
> >
> > --- albertjiang@yahoo.com wrote:
> > > Doesn't work with member variables that are
> > arrays.
> > >
> > >
> > >
> >
>
http://www.php.net/manual/function.get-class-vars.php
> > >
> > >
> > >
> > > --
> > > PHP Notes Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail:
> > > php-notes-unsubscribe@lists.php.net
> > > For additional commands, e-mail:
> > > php-notes-help@lists.php.net
> > > To contact the list administrators, e-mail:
> > > php-list-admin@lists.php.net
> > >
> >
> >
> > =====
> > --- Jesus M. Castagnetto (jcastagnetto@yahoo.com)
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Shopping - Thousands of Stores. Millions of
> > Products.
> > http://shopping.yahoo.com/
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Shopping - Thousands of Stores. Millions of
> Products.
> http://shopping.yahoo.com/
=====
--- Jesus M. Castagnetto (jcastagnetto@yahoo.com)
__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/