10/30/2022 0 Comments Locad a class definition in php![]() ![]() Locad a class definition in php code#(I've left out the actual code to do the selection/insertion). Why would I do this? Because I have my class layouts the same as their respective tables the factory then selects the data (making sure that the variables match) and plugs in the data. As long as LFPLayout exists somewhere in the scripts, get_declared_classes() will find it. This class looks to see if the class exists, then instantiates it - a declared class is not the same as an instantiated class. $new_obj = $r->object // this is a LFPLayout object. ![]() $r = new LFPDataFactory("class=LFPLayout,table=layout") If (in_array(strtolower($this->class), get_declared_classes())) $this->unpackArgs($args) // assigns locals from $args # Loads data from a table into a class object Printf ( "Type for \$b: %s\n", get_class ( $b )) Printf ( "Type for \$a: %s\n", get_class ( $a )) This requires me to have a find() method in every child class, but it does work. The only way I've found to get the child class name is to use the debug_traceback() function. As you've found, this appears to be impossible to get in an easy fashion. Since find() is usually called as a static method, it needs to know the name of the child class. One of the functions in the base class is a find() method that returns instances of the child classes. I have a base class that manages database tasks for a number of child classes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |