3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Object { // protected $hasMany; protected $theSignificativeProperties = ['nome', 'login']; public function getHasMany() { return $this->hasMany; } public function getSignificativeProperties() { return $this->theSignificativeProperties; } } class Aluno extends Object { private $nome; private $login; protected $hasMany = ['post', 'disciplina']; protected $theSignificativeProperties = ['nome', 'login']; /*public function getHasMany() { return $this->hasMany; }*/ /*public function getSignificativeProperties() { return $this->theSignificativeProperties; }*/ } class Post extends Object { // } class Disciplina extends Object { protected $hasMany = ['aluno']; } class EntityManager { // } class RelationalEntityManager extends EntityManager { public function find() { // echo 'Usando o RelationalEntityManager.'; } } class BaseController { private $objectService; public function __construct() { $this->objectService = new BaseObjectService(new RelationalEntityManager()); } public function view() { $args = func_get_args(); $this->objectService->view($args); } } class BaseObjectService { public function __construct(EntityManager $em) { // } public function view($args) { // echo 'Argumentos: '; print_r($args); $em->find(); } } echo 'Aluno: ' . class_exists('Aluno') . '<br>'; echo 'Teste: '; var_dump(class_exists('Teste')) . '\n'; $a = new Aluno(); print_r ( $a->getSignificativeProperties() ); $controller = new BaseController(); $controller->view('marcelo', 'boi', 1);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Cannot use 'Object' as class name as it is reserved in /in/5UJqS on line 3
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: Cannot use 'Object' as class name as it is reserved in /in/5UJqS on line 3
Process exited with code 255.
Output for 7.0.5 - 7.0.20, 7.1.0 - 7.1.25
Aluno: 1<br>Teste: bool(false) Array ( [0] => nome [1] => login ) Argumentos: Array ( [0] => marcelo [1] => boi [2] => 1 ) Notice: Undefined variable: em in /in/5UJqS on line 80 Fatal error: Uncaught Error: Call to a member function find() on null in /in/5UJqS:80 Stack trace: #0 /in/5UJqS(65): BaseObjectService->view(Array) #1 /in/5UJqS(93): BaseController->view('marcelo', 'boi', 1) #2 {main} thrown in /in/5UJqS on line 80
Process exited with code 255.
Output for 7.0.0 - 7.0.4
Aluno: 1<br>Teste: bool(false) Array ( [0] => nome [1] => login ) Argumentos: Array ( [0] => marcelo [1] => boi [2] => 1 ) Notice: Undefined variable: em in /in/5UJqS on line 80 Fatal error: Uncaught Error: Call to a member function find() on unknown in /in/5UJqS:80 Stack trace: #0 /in/5UJqS(65): BaseObjectService->view(Array) #1 /in/5UJqS(93): BaseController->view('marcelo', 'boi', 1) #2 {main} thrown in /in/5UJqS on line 80
Process exited with code 255.

preferences:
169.11 ms | 401 KiB | 188 Q