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 Maurice Ullrich  >  phpGlobalRef  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example
Class: phpGlobalRef
Handle objects referenced by global variables
Author: By
Last change:
Date: 2003-05-05 15:52
Size: 1,289 bytes
 

Contents

Class file image Download
<?php
/* Example for phpGlobalRef


*/
include_once("phpglobalref.php");
class 
class1{
var 
$Ref;
var 
$Class2_ref;

    function 
class1()
    {
        
$this->Ref = new phpGlobalRef;
    }

    function 
getclass2()
    {
        
$this->Class2_ref = &$this->Ref->getRef("class2");
    }

    function 
class2counter()
    {
        
$this->Class2_ref->classcounter();
    }
}

class 
class2{
var 
$Ref;
var 
$Counter;

    function 
class2()
    {
        
$this->Counter 0;
    }

    function 
classcounter()
    {
        
$this->Counter++;
        echo 
$this->Counter;
    }
}

// Create Class1 ,Class2 and phpGlobalRef
$Class1    =    new class1;
$Class2    =    new class2;
$Ref    =    new phpGlobalRef;

// Add class2 to Globalref    (!MUST be added from outside the class to get a real reference!)
$Ref->addRef($Class2"class2");

// Add reference of class2 to class1
$Class1->getclass2(); // Or $Class1->Class2_ref = &$Ref->getRef("class2");

// Run class2::classname with the class1 object
$Class1->Class2_ref->classcounter();

// call class2::classname to increment counter and see if Class2_ref is a reference of class2
$Class2->classcounter();
$Class2->classcounter();

// Run class2::classname with the class1 object again
$Class1->class2counter();

/* Output must be:
1234 if ok or
1122 if something went wrong
*/
?>