Re: get_class_vars() returned information ORDER
| From: | Patrick Schaaf | Date: | Sun, 09 Sep 2012 19:32:28 +0000 |
| Subject: | Re: get_class_vars() returned information ORDER | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62921@lists.php.net to get a copy of this message | ||
Thanks Sherif and all, for your answers.
So I will not rely on the order returned by get_class_vars (or
get_class_methods), instead adding suitable code (actually
roughly one additional line per class involved) to define my
desired ordering by hand.
If you're curious, the use case I was thinking of, arose when
implementing a logfile message formatting class hierarchy, where
subclasses represent individual logfiles with different pieces of
information that might be added to the logfile lines, in addition to the
base message - stuff like PHP_SELF, the calling user, memory usage etc.
I implement each of these different pieces as a separate trait with a
formatting function of a certain prefix, and imagined I could just use
the order of "use" statements in my subclasses, or as a proxy the method
order, to stably define the order in which the pieces will the show in
the logfile represented by that subclass.
Now, I add a static::$order array to each subclass, where I name the
pieces again (in addition to the use statements).
best regards
Patrick