3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class SourceTransformingLoader extends php_user_filter { /** * Php filter definition */ const PHP_FILTER_READ = 'php://filter/read='; /** * Default PHP filter name for registration */ const FILTER_IDENTIFIER = 'go.source.transforming.loader'; /** * String buffer * * @var string */ protected $data = ''; /** * Identifier of filter * * @var string */ protected static $filterId; /** * Register current loader as stream filter in PHP * * @param string $filterId Identifier for the filter * @throws \RuntimeException If registration was failed */ public static function register($filterId = self::FILTER_IDENTIFIER) { if (!empty(self::$filterId)) { throw new RuntimeException('Stream filter already registered'); } $result = stream_filter_register($filterId, __CLASS__); if (!$result) { throw new RuntimeException('Stream filter was not registered'); } self::$filterId = $filterId; } /** * {@inheritdoc} */ public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { $this->data .= $bucket->data; } if ($closing || feof($this->stream)) { $consumed = strlen($this->data); $bucket = stream_bucket_new($this->stream, strtoupper($this->data)); stream_bucket_append($out, $bucket); return PSFS_PASS_ON; } return PSFS_FEED_ME; } } SourceTransformingLoader::register(); function autoload($className) { echo file_get_contents('php://filter/read=go.source.transforming.loader/resource=' . __FILE__); eval("class $className {}"); } function shutdown() { $test = new TestClass(); // trigger autoload } register_shutdown_function('shutdown'); spl_autoload_register('autoload');
Output for 5.1.3 - 7.1.0
<?PHP CLASS SOURCETRANSFORMINGLOADER EXTENDS PHP_USER_FILTER { /** * PHP FILTER DEFINITION */ CONST PHP_FILTER_READ = 'PHP://FILTER/READ='; /** * DEFAULT PHP FILTER NAME FOR REGISTRATION */ CONST FILTER_IDENTIFIER = 'GO.SOURCE.TRANSFORMING.LOADER'; /** * STRING BUFFER * * @VAR STRING */ PROTECTED $DATA = ''; /** * IDENTIFIER OF FILTER * * @VAR STRING */ PROTECTED STATIC $FILTERID; /** * REGISTER CURRENT LOADER AS STREAM FILTER IN PHP * * @PARAM STRING $FILTERID IDENTIFIER FOR THE FILTER * @THROWS \RUNTIMEEXCEPTION IF REGISTRATION WAS FAILED */ PUBLIC STATIC FUNCTION REGISTER($FILTERID = SELF::FILTER_IDENTIFIER) { IF (!EMPTY(SELF::$FILTERID)) { THROW NEW RUNTIMEEXCEPTION('STREAM FILTER ALREADY REGISTERED'); } $RESULT = STREAM_FILTER_REGISTER($FILTERID, __CLASS__); IF (!$RESULT) { THROW NEW RUNTIMEEXCEPTION('STREAM FILTER WAS NOT REGISTERED'); } SELF::$FILTERID = $FILTERID; } /** * {@INHERITDOC} */ PUBLIC FUNCTION FILTER($IN, $OUT, &$CONSUMED, $CLOSING) { WHILE ($BUCKET = STREAM_BUCKET_MAKE_WRITEABLE($IN)) { $THIS->DATA .= $BUCKET->DATA; } IF ($CLOSING || FEOF($THIS->STREAM)) { $CONSUMED = STRLEN($THIS->DATA); $BUCKET = STREAM_BUCKET_NEW($THIS->STREAM, STRTOUPPER($THIS->DATA)); STREAM_BUCKET_APPEND($OUT, $BUCKET); RETURN PSFS_PASS_ON; } RETURN PSFS_FEED_ME; } } SOURCETRANSFORMINGLOADER::REGISTER(); FUNCTION AUTOLOAD($CLASSNAME) { ECHO FILE_GET_CONTENTS('PHP://FILTER/READ=GO.SOURCE.TRANSFORMING.LOADER/RESOURCE=' . __FILE__); EVAL("CLASS $CLASSNAME {}"); } FUNCTION SHUTDOWN() { $TEST = NEW TESTCLASS(); // TRIGGER AUTOLOAD } REGISTER_SHUTDOWN_FUNCTION('SHUTDOWN'); SPL_AUTOLOAD_REGISTER('AUTOLOAD');
Output for 5.1.0 - 5.1.2

Process exited with code 137.
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function spl_autoload_register() in /in/ToeLi on line 87 Fatal error: Class 'TestClass' not found in /in/ToeLi on line 83
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ToeLi on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ToeLi on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/ToeLi on line 8
Process exited with code 255.