PHP Classes

StructObject: Create objects from list of strict type variables

Recommend this page to a friend!
  Info   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 328 All time: 7,160 This week: 560Up
Version License PHP version Categories
structobject 1.0GNU General Publi...5.0PHP 5, Data types


This class can be used to create objects from list of strict type variables.

It takes a string with the names of types of variables that the current object should have.

The class only allows setting such variables to values of the specified types. The variables may not be unset.

Innovation Award
PHP Programming Innovation award nominee
July 2009
Number 12
Sometimes you need to use objects just for the purpose of passing of group or properties with values that have to be of specific types.

This class provides a way to create objects with variables that can only be set to values of types defined in a specification string.

Manuel Lemos
Picture of Benjamin Falk
Name: Benjamin Falk <contact>
Classes: 3 packages by
Country: Austria Austria
Age: 34
All time rank: 115411 in Austria Austria
Week rank: 161 Up1 in Austria Austria Up
Innovation award
Innovation award
Nominee: 3x


=== What is StructObject === StructObject is a PHP-Class what behaviors a little bit like the struct in C/C++. === Where does this class come from === This class comes from my CMS Ciwii which is not released yet. === How to use StructObject === It is simple. You create a new instance of StructObject and define your properties, like this: <?php require_once "Struct.php"; $struct = new StructObject ( "property1, property2 = with default value, property3 = ' with another default value ', property4A = Default-Value, property5:integer = 5" ); ?> So, there are many ways to define a property. You can even define a property with multiple allowed types: <?php //Code from above $struct2 = new StructObject ( "property:string:integer" ); ?> To get its value, you call it like a real property: <?php //Code from above echo $struct->property2; ?> The absolute-variant gets initialized when writing an upper A to the end of property-name. Now you can set values to the property. In our example: <?php //Code from above $struct->property4 = "Hello world"; ?> If you want to output the content of the property, you can write the example above. If you only want to output the content, if it is not default, write an upper A to the end of its name: <?php /* If value of $struct->propertyA would be Default-Value ** an empty string would get returned */ echo $struct->property4A; ?> Another feature is a strict class-type as property-value. To define something like that: <?php $struct3 = new StructObject ( "property:object[MyClass]" ); ?> Now the following lines would stop executing the script with an error-message: <?php //Code from above $struct3->property = 'a string'; ?>

  Files folder image Files  
File Role Description
Accessible without login Plain text file Struct.php Class Main-file
Accessible without login Plain text file example.php Example Example
Accessible without login Plain text file example2.php Example Creating your own Class by extending StructObject
Accessible without login Plain text file LICENCE Lic. GNU-Licence
Accessible without login Plain text file README Doc. Tutorial

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:7,160
This week:560Up