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 the class structure of Bones

Let's start building out the Bones class by adding the following code to the lib/bones.php file inside our working directory:

/Library/Webserver/Documents/verge/lib/bones.php

<?php
class Bones {
private static $instance;
public static $route_found = false;
public $route = '';
public static function get_instance() {
if (!isset(self::$instance)) {
self::$instance = new Bones();
}
return self::$instance;
}

What just happened?

We just created our Bones class, added a few private and public variables, and a strange function called get_instance(). The private static variable $instance, mixed with the function get_instance(), forms something that is called The Singleton Pattern.

The Singleton Pattern ...

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