stdClass
In case anybody didn't catch it, stdClass is the base php class, form which all other classes are actually extended. This gives the basics of default methods and properties, and is an inherint concept in class type data structures.
The reason you see it so much in mambo is becuase mambo developers have decided to use stdClass type objects as configuration/information repositories instead or parrallel variables or arrays. These objects are used exclusively for run time storage of variables (just for their set and get abilities.)
They actually get quite ugly if you turn your php alerts on (as most of us do when we develop,) as you can see an alert for each call to a variable that has yet to be set.
This is actually a beef of mine here. The use of these empty objects, with attributes set at runtime (as opposed to being declared as a part of the class) generate a few problems:
1) the only bug I've ever found in PHP4 was with respect to refering undeclared object properties which used to trip out php4, and give you an error relating to a completely different bit of code - although that might have required the properties to be returned by reference, I can't rememeber.
2) you can never really see what the object is like/supposed to be like if it isn't set up properly. Similarily the object can never be tested for vailidty before being passed on.
3) all occurences of such objects are completely non-differentiable (sp?) You can't tell if two are meant for the same purpose or if they are for different purposes.
I'm not much of a programmer but I think it would be much better to use a base class defined for this use, which has some understanding of what it stores and can perhaps self-validate and self manage (and print itself out.)
I wrote a php4 object of such a nature which I called a struct. It is an abstracted class, which when extended is told what kind of information it holds. It then spend it's existence setting and retrieving the values it is meant to hold, in essence serving it's purpose an a configuration information repository. In addition it can self-validate ( $obj->isValid(); ), return meta inforamtion on itself and it's variables and .... that's it actually.
Of course my code is made irrelevant by php5 which actually handles the sets and gets much better (but still would require a base abstract class.)
ok - enough of my blab.
|