file: ClassUser.php
[cc lang=”php” escaped=”true” width=”500″]
setExample(“example sucks”);
echo($class_instance->getExample());

$class_instance->NewProperty = “You just created a new propertey of the class, that is not defined per default”;
$class_instance->AnotherProperty = “You just created a new propertey of the class, that is not defined per default”;

?>
[/cc]
file: ExampleClass.php
[cc lang=”php” escaped=”true” width=”500″]
example = $data;
$this->another_var = $data;
}

public function getExample() {
return $this->example;
}

public function setExample($example) {
$this->example = $example;
}

public function exampleFunction() {
$test = $this->example; // now that you have a private $example, this will work
$another_test = $this->another_var; //this obviously does
}

/* let’s you dynamically generate new properties */
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
}
}

public function __set($property, $value) {
if (!property_exists($this, $property)) {
$this->$property = $value;
}

return $this;
}

}
?>
[/cc]

output is:

"$class_instance" (ExampleClass)
-> another_var = 
-> example = example sucks
-> NewProperty = You just created a new propertey of the class, that is not defined per default
-> AnotherProperty = You just created a new propertey of the class, that is not defined per default
admin