PostgreSQL & PHP Tutorials - Extending Your Classes
PHP »
Introduction to Object Oriented Programming
As with other programming languages, you can easily extend classes and objects:
<?php
class a {
function __construct() {
// this gets called in php5.
echo "I am in function " . __FUNCTION__ . " of class " . __CLASS__ . "<br/>";
}
function a() {
// this gets called in php4.
// we'll have to call the constructor ourselves.
$this->__construct();
}
}
class b extends a {
}
$my_class = new b();
?>
The 'extends' keyword means 'class b' inherits all of 'class a' properties and methods (methods are simply 'functions' inside a class).
We haven't actually defined anything in 'class b' yet - so php will go back to 'class a' to see what we need to do.
If you run this through your browser you will see:
I am in function __construct of class a
Avg Rating: 4
Vote Count: 10
