![]() |
|
PHP classes and objects. Free online PHP and MySQL Web Database Programming Tutorial... |
| Lessons | PHP Classes and Objects |
|
|
Classes and objects in PHP are very similar to Java. A variable of the desired type is created using the new operator. Just like Java, PHP supports single inheritance only and uses the keyword extends to inherit from a super class. The inherited methods and members can be overridden, unless the parent class has declared a method as final. A simple PHP class is defined as under: <?php class Student { var $name; // name of the student var $class; // class of the student var $GPA; // GPA of the student function printName() { echo $this->name; } function printClass() { echo $this->class; } function printGPA() { echo $this->GPA; } } } ?>
Next: PHP $_get
|