note 43363 added to ref.classobj
| From: | ettinger at consultant dot com | Date: | Fri, 18 Jun 2004 20:59:05 +0000 |
| Subject: | note 43363 added to ref.classobj | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-71299@lists.php.net to get a copy of this message | ||
Re: Looking for an uninstantiated class
# Loads data from a table into a class object
class LFPDataFactory extends LFPObject {
var $object;
var $class;
var $table;
function LFPDataFactory($args) {
$this->unpackArgs($args); // assigns locals from $args
if (in_array(strtolower($this->class), get_declared_classes())) {
$this->object = new $this->class;
// assemble the columns in the table...
// select their values and put them in our new object...
} else { trigger_error("Class ".$this->class." not found",
E_USER_ERROR); }
}
}
$r = new LFPDataFactory("class=LFPLayout,table=layout");
$new_obj = $r->object; // this is a LFPLayout object.
print_r($new_obj);
This class looks to see if the class exists, then instantiates it -- a declared class is not the
same as an instantiated class. As long as LFPLayout exists somewhere in the scripts,
get_declared_classes() will find it. Remember strtolower on compare, however.
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.
(I've left out the actual code to do the selection/insertion).
----
Manual Page -- http://www.php.net/manual/en/ref.classobj.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43363
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43363&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43363&report=yes
Search -- http://master.php.net/manage/user-notes.php