1. class stdObject {
  2. public function __construct(array $arguments = array()) {
  3. if (!empty($arguments)) {
  4. foreach ($arguments as $property => $argument) {
  5. $this->{$property} = $argument;
  6. }
  7. }
  8. }
  9. public function __call($method, $arguments) {
  10. $arguments = array_merge(array("stdObject" => $this), $arguments); // Note: method argument 0 will always referred to the main class ($this).
  11. if (isset($this->{$method}) && is_callable($this->{$method})) {
  12. return call_user_func_array($this->{$method}, $arguments);
  13. } else {
  14. throw new Exception("Fatal error: Call to undefined method stdObject::{$method}()");
  15. }
  16. }
  17. }
  18. $obj = new stdObject();
  19. $obj->navn = "John";
  20. $obj->efternavn = "Doe";
  21. $obj->alder = 20;
  22. $obj->adresse = null;
  23. $obj->getInfo = function($stdObject) { // $stdObject referred to this object (stdObject).
  24. echo $stdObject->navn . " " . $stdObject->efternavn . " er " . $stdObject->alder . " år gammel. Og lever på " . $stdObject->adresse;
  25. };