<?php
$a = [
new Person('thomas', 'gutbier'),
new Person('mathhias', 'gutbier'),
new Person('ursula', 'breidenstein'),
new Person('salbert', 'friemel')
];
foreach ($a as $person) {
echo $person;
}
class Person {
public $name;
public $vorname;
public function __construct ($name, $vorname)
{
$this->name = $name;
$this->vorname = $vorname;
}
public function renderPerson ()
{
return $this->vorname . ' ' . $this->name . "\n";
}
public function __toString()
{
return $this->renderPerson();
}
}
Fatal error: Uncaught Error: Class "Person" not found in /in/fOQ8R:3
Stack trace:
#0 {main}
thrown in /in/fOQ8R on line 3
Process exited with code 255.