<?php
class NewClass
{
public $id;
//here's your registry
protected static $registry = array();
public function __construct($id)
{
$this->id = $id;
$this->checkVars();
//if not failed, add to registry:
self::$registry[] = $id;
}
public function checkVars()
{
if (empty($this->id))
{
trigger_error('ID is a required parameter.');
}
//checking if it's already used:
elseif (in_array($this->id, self::$registry))
{
trigger_error('ID "'.$this->id.'" was used already. Please insert a unique name.');
}
}
}
$object1 = new NewClass('id1');
$object2 = new NewClass('id2');
$object3 = new NewClass('id1');
Notice: ID "id1" was used already. Please insert a unique name. in /in/lUX2P on line 26
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/lUX2P on line 4
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/lUX2P on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/lUX2P on line 4
Process exited with code 255.