OOP question in PHP4
| From: | Lukasz Michalski | Date: | Wed, 24 May 2000 18:53:36 +0000 |
| Subject: | OOP question in PHP4 | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-464@lists.php.net to get a copy of this message | ||
Hi,
Got OOP problem maybe somebody solved it before.....
------------------------------------
//two classes:
class parent {
var $a;
function save($db) {
$pa = prepare($a);
$db -> query("INSERT INTO children (a,b) VALUES($pa,NULL)");
}
}
class child extends parent {
var $b;
function save($db) {
$pa = prepare($a);
$pb = prepare($b);
$db -> query("INSERT INTO children (a,b) VALUES($pa,$pb)");
}
};
//And sql table:
CREATE table children (a int, b int);
-------------------------------------
making preapare($a) in child class is inlogical becouse it should be
done in parent class. Child class also shouldn't mess with vars which
belongs to parent class (like inserting them into database) - this
should be done in parent class to which that vars belongs.
Only solution to this problem I've founded is to make Insert into parent
class and update into all classes that inherits from it.
Any good methods to do save($db) with one SQL INSERT regardless of
inheritance level and with all limitations described above?
(besides ODBS server)
thans for help.
--
Łukasz Michalski
mailto:zork@clan.pl