4.2. Building Classes
Now that you have learned about the theoretical background of object-oriented software development, it is time to return to PHP-specific subject matter.
In this section you will learn to write your own PHP classes and you will see how inheritance and function overloading can be done in PHP.
4.2.1. A Simple Class
Writing classes in PHP is as simple as writing functions. However, some things have to be taken into consideration when working with classes and instances.
The following piece of code shows the class called human, which stores information all human beings have in common:
<?php # Class human class human { var $age; var $gender; # Constructor function human() { # an empty constructor } # Setting the age of a person ...
Get PHP and PostgreSQL: Advanced Web Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.