3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 { private $em; public function __construct(EntityManager $entityManager) { $this->$em = $entityManager; } 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);
based on 5UJqS
Output for 7.2.0 - 7.3.0rc3
Fatal error: Cannot use 'Object' as class name as it is reserved in /in/eJfL1 on line 3
Process exited with code 255.
Output for 7.1.0 - 7.1.20
Aluno: 1<br>Teste: bool(false) Array ( [0] => nome [1] => login ) Notice: Undefined variable: em in /in/eJfL1 on line 74 Argumentos: Array ( [0] => marcelo [1] => boi [2] => 1 ) Notice: Undefined variable: em in /in/eJfL1 on line 82 Fatal error: Uncaught Error: Call to a member function find() on null in /in/eJfL1:82 Stack trace: #0 /in/eJfL1(65): BaseObjectService->view(Array) #1 /in/eJfL1(95): BaseController->view('marcelo', 'boi', 1) #2 {main} thrown in /in/eJfL1 on line 82
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Aluno: 1<br>Teste: bool(false) Array ( [0] => nome [1] => login ) Notice: Undefined variable: em in /in/eJfL1 on line 74 Fatal error: Uncaught Error: Cannot access empty property in /in/eJfL1:74 Stack trace: #0 /in/eJfL1(60): BaseObjectService->__construct(Object(RelationalEntityManager)) #1 /in/eJfL1(94): BaseController->__construct() #2 {main} thrown in /in/eJfL1 on line 74
Process exited with code 255.
Output for hhvm-3.15.4
Aluno: 1<br>Teste: bool(false) Array ( [0] => nome [1] => login ) Notice: Undefined variable: em in /in/eJfL1 on line 74 Fatal error: Uncaught Error: Cannot access empty property in /in/eJfL1:74 Stack trace: #0 /in/eJfL1(60): BaseObjectService->__construct() #1 /in/eJfL1(94): BaseController->__construct() #2 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Aluno: 1<br>Teste: bool(false) Array ( [0] => nome [1] => login ) Notice: Undefined variable: em in /in/eJfL1 on line 74 Fatal error: Cannot access empty property in /in/eJfL1 on line 74
Process exited with code 255.