<?php
//Include pclib framework
require 'pclib/pclib.php';
use pclib\system\BaseObject;
print "<h2>Using pclib BaseObject</h2>";
print "You can derive your objects from BaseObject for additional features. (see source)<br><br>";
class Dog extends BaseObject
{
public $name;
public $color = 'black';
public $doTrick = null;
function __construct($name)
{
parent::__construct();
$this->name = $name;
}
function bark()
{
print "Bark! Bark!<br>";
//trigger dog event
$this->trigger('dog.bark');
}
};
//Preset default public values of class Dog.
Dog::defaults('color', 'white');
println("Create Dog object.");
$dog = new Dog('Rex');
println("$dog->name color is $dog->color.");
$dog->bark();
//You can use events on your object!
$dog->on('dog.bark', function($e) { print "Niiice dog.<br>";});
$dog->bark();
//Assign and call anonymous functions easy way.
$dog->doTrick = function() use($dog) { print $dog->name . " is rolling on the floor."; };
$dog->doTrick();
//Validate not existing members of the class.
//print $dog->test; //throws pclib\MemberAccessException (undeclared property)
function println($s)
{
print "<p>$s</p>";
}
?>
Elapsed time: 11.55 ms