PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Benjamin Falk   StructObject   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example
Class: StructObject
Create objects from list of strict type variables
Author: By
Last change: Added an example for the new feature
Date: 15 years ago
Size: 1,082 bytes
 

Contents

Class file image Download
<?php
   
require_once "Struct.php";
   
   
//Defining a class
   
class anyThing
   
{
        public
$var='Class';
    }
   
   
//Create a new Struct-instance
   
$struct = new StructObject (
       
"property1:string,
         property2 = Hello,
         property3 = ' World!',
         property4A = Default-Value,
         anything:object[anyThing],
         number:integer = 0"
   
);
   
   
//Output text
   
$struct->property1 = 'Robert says: ';
    echo
$struct->property1;
    echo
$struct->property2 . $struct->property3;
   
    echo
"<br />\n";
   
   
//Absolute-Variant:
   
echo $struct->property4."<br />\n"; //Default-Value is the output
   
echo $struct->property4A."<br />\n"; //Absolute-Variant output: nothing, because property has default-value
   
   
$struct->property4 = 'No-Default-Value';
    echo
$struct->property4A."<br />\n"; //Property has a no-default value, so it gets output
   
   
$struct->anything = new anyThing; //Property anything has to get instances from anyThing
   
echo $struct->anything->var."<br />";
   
   
//What happens if we give the property number a string-value
   
$struct->number = "Hello world!";
?>