PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Marco Marchiņ   Class Prototype   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: test
Class: Class Prototype
Define variables of all class objects dynamically
Author: By
Last change:
Date: 14 years ago
Size: 714 bytes
 

Contents

Class file image Download
<?php
require "classPrototype.php";

class
test extends classPrototype
{
    var
$a=2;
   
    var
$b=3;
   
    function
_construct(){
       
parent::_construct();
    }
}

$test=new test();
$test->prototype->a=4;

$test2=new test();
$test->prototype->c=4;

echo
$test->a; //A on $test is 2 because it was assigned before the changing of the prototype
echo $test2->a; //A on $test2 is 4 because the object has been initialized after the changing of the prototype

echo $test->b;
echo
$test2->b; //B is 3 on both objects because it hasn't been changed

echo $test->c;
echo
$test2->c; //C is 4 on both objects because it wasn't defined before the assignment on the prototype so every instance has taken it
?>