Login   Register  
PHP Classes
elePHPant
Icontem

File: test_03_objects.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of n/a  >  Cache output and objects  >  test_03_objects.php  >  Download  
File: test_03_objects.php
Role: Example script
Content type: text/plain
Description: Caching objects
Class: Cache output and objects
Cache the output of PHP scripts in files
Author: By
Last change:
Date: 7 years ago
Size: 1,204 bytes
 

Contents

Class file image Download
<?
/*

With Cache object you can cache objects!
Objects need to be defined before cache block and sent as array of
  object references (using '&' operator) in third parameter of save function.
*/

class cTest
{
    function 
cTest($a,$b,$c)
    {
        
$this->$a;
        
$this->$b;
        
$this->$c;
    }
    
    function 
foo()
    {
        echo(
"FOO: a = ".$this->a."; b = ".$this->b."; c = ".$this->c."<br>");
    }
}

$foo01 = new cTest("A","B","C");
$foo02 = new cTest("1","2","3");
$foo03 = new cTest("x","y","z");

$foo01->foo();
$foo02->foo();
$foo03->foo();
echo 
"<br>";

require_once(
"cache.php");

$path ".";
$cache = new Cache($path);


while(
$cache->save("cache.test_04.tmp",10,array(&$foo01,&$foo02,&$foo03)))
{
    echo(
"<b>This part is executed every 10 seconds</b><br>");
    
    
$foo01->"bar ".rand(0100);
    
$foo02->$foo02->a.$foo02->b.$foo02->c;
    
$foo02->"This is changed at ".date("H:i:s");
    
    echo(
date("H:i:s")."<br>");
    
}

echo(
"<b>This part is executed every time</b><br>");
echo(
date("H:i:s")."<br>");

echo(
"<br><i>Values in objects should be different than on start of file...</i><br>");
$foo01->foo();
$foo02->foo();
$foo03->foo();
    

?>