PHP Classes

File: example2.php

Recommend this page to a friend!
  Classes of Benjamin Falk   StructObject   example2.php   Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: Creating your own Class by extending StructObject
Class: StructObject
Create objects from list of strict type variables
Author: By
Last change: ...
Date: 15 years ago
Size: 969 bytes
 

Contents

Class file image Download
<?php
   
/*
    ** Let's use StructObject directly in a new object
    */
   
    //Load the struct-file
   
require_once 'Struct.php';
   
   
//Create your own class and extend it with StructObject
   
class MyClass extends StructObject
   
{
       
/*
        ** properties:
        ** title:string
        ** content:string
        ** count:integer
        */
       
        /*
        ** The output of the properties
        */
       
public function output()
        {
            echo
"<h1>".htmlentities($this->title)."</h1>";
            echo
"<p>".htmlentities($this->content)."</p>";
        }
       
       
//And the rest your code
       
        /*
        ** @magic This function gets called on creating an instance
        */
       
function __construct()
        {
           
parent::__construct(
               
"title:string,
                 content:string,
                 count:integer"
           
);
        }
    }
   
   
//Now we can create a new instance from our class
   
$my = new MyClass;
   
$my->title = "This is the second example";
   
$my->content = "Just a little example";
   
$my->count = 10;
   
$my->output();
?>