Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Chris Pliakas  >  Object and Variable Registry  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example of registry
Class: Object and Variable Registry
Register variables for use in any scope
Author: By
Last change:
Date: 2007-04-16 16:30
Size: 1,072 bytes
 

Contents

Class file image Download
<?php

///////////////////////////////////////
// Example of how `registry` can be
// used to retrieve variables within
// any scope of the application.
///////////////////////////////////////

//calls registry class
require_once 'registry.php';

//sets and registers a variable
$item 'Here is a registered variable';
registry::add('Variable'$item);

/**
* Test class that echos a registered variable
*/
class test
{
    private 
$item;

    public function 
__construct()
    {
        
$this->item registry::get('Variable');
    }

    public function 
get()
    {
        echo 
'<p>'.$this->item.'</p>';
    }
}

//will return "Here is a registered variable"
$test = new test();
$test->get();

//tests if "Variable" exists
if (registry::exists('Variable')) {
    echo 
'<p>"Variable" exists</p>';
} else {
    echo 
'<p>"Variable" does not exists</p>';
}

//tests if "variable" exists
if (registry::exists('variable')) {
    echo 
'<p>"variable" exists</p>';
} else {
    echo 
'<p>"variable" does not exists</p>';
}

//removes "Variable"
registry::remove('Variable');

?>