WHOA... KEEP IT SIMPLE!
In regards to secure_admin's note: You've used OOP to simplify PHP's ability to create and use object references. Now use PHP's static keyword to simplify your OOP.
<?php
class DataModelControl {
protected static $data = 256; // default value;
protected $name;
public function __construct($dmcName) {
$this->name = $dmcName;
}
public static function setData($dmcData) {
if(is_numeric($dmcData)) {
self::$data = $dmcData;
}
}
public function __toString() {
return "DataModelControl [name=$this->name, data=" . self::$data . "]";
}
}
# create several instances of DataModelControl...
$dmc1 = new DataModelControl('dmc1');
$dmc2 = new DataModelControl('dmc2');
$dmc3 = new DataModelControl('dmc3');
echo $dmc1 . '<br>';
echo $dmc2 . '<br>';
echo $dmc3 . '<br><br>';
# To change data, use any DataModelControl object...
$dmc2->setData(512);
# Or, call setData() directly from the class...
DataModelControl::setData(1024);
echo $dmc1 . '<br>';
echo $dmc2 . '<br>';
echo $dmc3 . '<br><br>';
?>
DataModelControl [name=dmc1, data=256]
DataModelControl [name=dmc2, data=256]
DataModelControl [name=dmc3, data=256]
DataModelControl [name=dmc1, data=1024]
DataModelControl [name=dmc2, data=1024]
DataModelControl [name=dmc3, data=1024]
... even better! Now, PHP creates one copy of $data, that is shared amongst all DataModelControl objects.
----
Server IP: 69.147.83.197
Probable Submitter: 67.150.0.127
----
Manual Page -- http://www.php.net/manual/en/language.oop5.references.php
Edit -- https://master.php.net/note/edit/86050
Del: integrated -- https://master.php.net/note/delete/86050/integrated
Del: useless -- https://master.php.net/note/delete/86050/useless
Del: bad code -- https://master.php.net/note/delete/86050/bad+code
Del: spam -- https://master.php.net/note/delete/86050/spam
Del: non-english -- https://master.php.net/note/delete/86050/non-english
Del: in docs -- https://master.php.net/note/delete/86050/in+docs
Del: other reasons-- https://master.php.net/note/delete/86050
Reject -- https://master.php.net/note/reject/86050
Search -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.