<?php
$test = new class {
public $a;
public $b = null;
public $c = "";
public function set($name)
{
$this->a[$name] = $name;
$this->b[$name] = $name;
$this->c[$name] = $name;
}
public function exec()
{
var_dump($this->a);
var_dump($this->b);
var_dump($this->c);
}
};
$test->write([1,2,3]);
$test->exec();
$test->write("test");
$test->exec();
$test->write(123456);
$test->exec();
Fatal error: Uncaught Error: Call to undefined method class@anonymous::write() in /in/iej6r:22
Stack trace:
#0 {main}
thrown in /in/iej6r on line 22
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Fatal error: Uncaught Error: Call to undefined method class@anonymous::write() in /in/iej6r:22
Stack trace:
#0 {main}
thrown in /in/iej6r on line 22
Process exited with code 255.
Output for 5.6.0 - 5.6.38
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/iej6r on line 2
Process exited with code 255.