O'Reilly logo

CouchDB and PHP Web Development Beginner's Guide by Tim Juravich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — creating a Base object

In this section, we will create a base class called base.php that all of our classes will inherit.

  1. Let's start by creating a new file called base.php, and placing it in the classes folder inside of the working directory (/Library/Webserver/Documents/verge/classes/base.php)
  2. Create an abstract class with a __construct function in base.php. On __construct of the object, let's take $type as an option, and set it to a protected variable also called $type.
    <?php
    abstract class Base
    {
    protected $type;
    public function __construct($type)
    {
    $this->type = $type;
    }
    }
    
  3. In order to facilitate the getting and setting of variables in our classes later, let's add the __get() and __set() functions right after the __construct ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required