note 15829 deleted from keyword.extends by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 20:35:11 +0000 |
| Subject: | note 15829 deleted from keyword.extends by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-21933@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" );
...
}
}
...
?>