3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php namespace One { class Request { public function getResponse() { return new Response(); } } class Response { public function __construct() { $debug = debug_backtrace(); if (count($debug) < 2 || !isset($debug[1]['class']) || strpos($debug[1]['class'], __NAMESPACE__ . '\\') !== 0) { die('Invalid context'); } echo 'Created' . PHP_EOL; } } } namespace Two { $request = new \One\Request(); $response = $request->getResponse(); // Should work $wrongResponse = new \One\Response(); // Should NOT work }
Output for 5.3.0 - 7.1.0
Created Invalid context
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/g0dnG on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/g0dnG on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/g0dnG on line 3
Process exited with code 255.