PHP Classes
Icontem

File: example2.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Benjamin Falk  >  StructObject  >  example2.php  
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
 

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();
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products