note 15829 added to keyword.extends
| From: | hartelaub at yahoo dot com | Date: | Thu, 04 Oct 2001 11:50:45 +0000 |
| Subject: | note 15829 added to keyword.extends | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18559@lists.php.net to get a copy of this message | ||
class extending - method overriding - php4 / mysql
$mydb is object of some db class,
db has table contacts(pk id, ...) and persons(pk id, 'fk' contact_id, last_name, ...) that
are represented by Contact and Person php objects. Person extends Contact.
in this case each contact is a person (and vice versa)
<?
$myperson = new Person( $mydb->selectUnique( "id where last_name='Smith'" )
);
...
$myperson->delete();
...
class Contact
{
var $id, ...;
function Contact( $id )
{
$this->id = $id;
...
}
...
function delete()
{
$mydb->delete( "from contact where id = $this->id" );
...
}
}
class Person extends Contact
{
var $id, $contact_id, ..;
function Person( $id )
{
$this->id = $id;
$this->contact_id = $mydb->selectUnique( "contact_id from persons where id =
$this->id" );
$this->Contact( $this->contact_id );
}
...
function delete()
{
Contact::delete();
$mydb->delete( "from persons where id = $this->id" );
...
}
}
...
?>
--
http://www.php.net/manual/en/keyword.extends.php
http://master.php.net/manage/user-notes.php?action=edit+15829
http://master.php.net/manage/user-notes.php?action=delete+15829
http://master.php.net/manage/user-notes.php?action=reject+15829