Autoload Class Class

function ter_autoload($class_name){ include $class_name . '.php'; }
spl_autoload_register('ter_autoload');
if(function_exists('__autoload')){ spl_autoload_register('__autoload'); }

$classname  = new ClassName();

Polyton Design Pattern

/*
* The Polyton Design Pattern
* By Adam J Nowak ~ http://hyperspatial.com
*
* Creates unique numbered class instances and allows you to run a different set of functions for the first instance of the class.
*
* Methods:
* create(); //Constructor method, Use: $polyton = Polyton::create('Test String');
* get_version(); //Instance version number, Use: $polyton->get_version();
* get_data(); //Value of the $_data class property, Use: $polyton->get_data();
* set_data(); //Set value of the $_data class property, Use: $polyton->set_data('New Test String');
*
* Create Instances:
* 1 - Use static method to instantiate
* 2 - Constructor is private. *Don't Use: $var = new Polyton('new polyton');
* 3 - The one argument is a simple string to demonstrate constructor argument flow
*/

class Polyton{
private static $instance;
private static $version;
private $_version;
private $_data;

private function __construct($data){
$this->_data = $data;
$this->_version = self::$version;
echo "Polyton $this->_version Constructed"; //Replace w/ constructor statements
}
public static function create($data){
if(!isset(self::$instance)){
self::$version = 1;
self::$instance = new Polyton($data); //Create original
echo ' ~ Original<br>'; //Replace w/ original instance statements
}
else{
self::$version ++;
self::$instance = new Polyton($data); //Create subsequent version
echo ' ~ Reproduction<br>'; //Replace w/ instance statements
}
return self::$instance;
}
public function get_version(){ return $this->_version; }
public function get_data(){ return $this->_data; }
public function set_data($new_data){
$this->_data = $new_data;
return $this->_data;
}
}

/*
* Polyton Design Pattern example markup
*
* Create Instances:
* 1 - Use static method to instantiate
* 2 - Constructor is private so you cant use: $var = new Polyton('new polyton');
* 3 - The one argument is a simple string to demonstrate constructor argument flow
*/

$polyton = Polyton::create('Top');
$polyton2 = Polyton::create('Middle');
$polyton3 = Polyton::create('I like to argue');

// Display info about the second object you created
echo '<br>Polyton 2 Info:<br>';
echo "Version = " . $polyton2->get_version() . '<br>';
echo "Data = " . $polyton2->get_data() . '<br>';

// Change the value of the stored argument
echo '<br>Polyton 2 data change:<br>';
$polyton2->set_data('The Very Middle');
echo "Changed Data = " . $polyton2->get_data() . '<br>';

?>

Objects for function arguments

<script type="text/javascript">

argumentObject = {arg1: "Argument One", arg2: "Argument Two", arg3: "Argument Three", arg4: "Argument Four"};

function argumentTest(objArgs){
alert(objArgs.arg1 + 'n' + objArgs.arg2 + 'n' + objArgs.arg3 + 'n' + objArgs.arg4);
}

argumentTest(argumentObject);

</script>

Customer Object

<?php
class Customer
{
private $_name;
private $_gender;
private $_details = "Empty";

//Setter Functions
function setName($name)
{
$this->_name = $name;
}
function setGender($gender)
{
$this->_gender = $gender;
}
//Getter Functions
function getName()
{
return($this->_name);
}
function getGender()
{
return($this->_gender);
}
function getDetails()
{
$this->_details = "A " . $this->_gender . " named " . $this->_name;
return($this->_details);
}
}

//Create some objects
$the_customer = new Customer();
$the_second_customer = new Customer();

$the_customer->setName('Timmy');
$the_customer->setGender('Male');

$the_second_customer->setName('Suzanna');
$the_second_customer->setGender('Female');

echo 'Customer 1 = ' . $the_customer->getDetails() . '<br>';
echo 'Customer 2 = ' . $the_second_customer->getDetails() . '<br>';
?>