Note: each tutorial contains information about one specific part of Spoon. If something is unclear, post a comment.

Introduction to Spoon

Written by Davy Hellemans -

Prerequisites

Nothing at all

Tutorial

Setting up Spoon

To be able to run Spoon, you need to add the absolute location of your library (containing Spoon) to your include path. Once you've done this, you're ready to go. Thanks to the autoloader, you will never need to require specific Spoon class files.

// define location of your library
define('PATH_LIBRARY', '/home/myUsername/library');

// add this to the include path
set_include_path(get_include_path() . PATH_SEPARATOR . PATH_LIBRARY);

// require spoon
require_once 'spoon/spoon.php';

In the next minor release, we're going to see if we can get rid of the include path hassle. Until then, this step is required to start using Spoon Library.

Dumping variable information

When developing/debugging it can come in handy to use a method to dump all the information available about a specific variable. Spoon::dump() is the perfect way to show this information. Works on all kind of variables (string, int, array, resource, object, ...).

// require Spoon class
require_once 'spoon/spoon.php';

// dump an object
$object = new Object();
Spoon::dump($object, false);

// dump a string/int/float
$string = 'spoon library';
$int = 13;
$float = 1.3;
Spoon::dump($string, false);
Spoon::dump($int, false);
Spoon::dump($float, false);

Object references

Spoon lets you store objects in some sort of internal registry. You can choose the name to point to each object stored. Three methods are available to set, get and delete these object references.

// require Spoon class
require_once 'spoon/spoon.php';

// create object
$object = new Object();

// add this object to the registry
Spoon::set('theNameIWant', $object);

// do something funky with the object
Spoon::get('theNameIWant')->someMethod();

// destroy the reference to this object
Spoon::set('theNameIWant');