e non è in quel modo che si utilizza __get()
Rispondo così:
Codice PHP:
//L'esempio di php.net
public function __get($name) {
echo "Getting '$name'\n";
if (array_key_exists($name, $this->data)) {
return $this->data[$name];
}
$trace = debug_backtrace(); trigger_error(
'Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
E_USER_NOTICE);
return null;
}
// Il mio esempio (Ho corretto una cosa, leggi dopo cosa)
public function __get ($property) {
switch ($property) {
case "prop1": return $this->prop1;
case "prop2": return $this->prop2;
case "prop3": return $this->prop3;
default:
$backtrace = debug_backtrace()[0];
trigger_error("Undefined property: OOString::\$" . $property . " in <b>" . $backtrace["file"] . "</b> on line <b>" . $backtrace["line"] . "</b><br/>", E_USER_NOTICE); // linea 87
}
}
A parte il fatto che php.net usa un array non cambia niente
Per il resto ho sbagliato a scrivere qui: ho messo le proprietà $prop1, $prop2, $prop3 all'interno di __get anziché della classe