3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class VariableStream { var $position; var $varname; function stream_open($path, $mode, $options, &$opened_path) { $url = parse_url($path); $this->varname = $url["host"]; $this->position = 0; return true; } function stream_read($count) { $ret = substr($GLOBALS[$this->varname], $this->position, $count); $this->position += strlen($ret); return $ret; } function stream_write($data) { $left = substr($GLOBALS[$this->varname], 0, $this->position); $right = substr($GLOBALS[$this->varname], $this->position + strlen($data)); $GLOBALS[$this->varname] = $left . $data . $right; $this->position += strlen($data); return strlen($data); } function stream_tell() { return $this->position; } function stream_eof() { return $this->position >= strlen($GLOBALS[$this->varname]); } function stream_seek($offset, $whence) { switch ($whence) { case SEEK_SET: if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) { $this->position = $offset; return true; } else { return false; } break; case SEEK_CUR: if ($offset >= 0) { $this->position += $offset; return true; } else { return false; } break; case SEEK_END: if (strlen($GLOBALS[$this->varname]) + $offset >= 0) { $this->position = strlen($GLOBALS[$this->varname]) + $offset; return true; } else { return false; } break; default: return false; } } function stream_metadata($path, $option, $var) { if($option == STREAM_META_TOUCH) { $url = parse_url($path); $varname = $url["host"]; if(!isset($GLOBALS[$varname])) { $GLOBALS[$varname] = ''; } return true; } return false; } } stream_wrapper_register("var", "VariableStream") or die("Failed to register protocol"); $myvar = ""; $fp = fopen("var://myvar", "r+"); fwrite($fp, "line1\n"); fwrite($fp, "line2\n"); fwrite($fp, "line3\n"); rewind($fp); while (!feof($fp)) { echo fgets($fp); } fclose($fp); var_dump($myvar);
Output for 4.3.2, 4.3.5 - 4.4.9, 5.1.3 - 7.1.0
line1 line2 line3 string(18) "line1 line2 line3 "
Output for 5.1.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5JuZt on line 3 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5JuZt on line 4 line1 line2 line3 string(18) "line1 line2 line3 "
Output for 5.0.0 - 5.0.5
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5JuZt on line 3 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/5JuZt on line 4 string(18) "line1 line2 line3 "
Output for 4.3.4
line1 line1 line3 string(18) "line1 line1 line3 " *** Error in `/bin/php-4.3.4': double free or corruption (fasttop): 0x0000000002082550 *** ======= Backtrace: ========= /usr/lib/libc.so.6(+0x6f364)[0x7fe2bdfa0364] /usr/lib/libc.so.6(+0x74d96)[0x7fe2bdfa5d96] /usr/lib/libc.so.6(+0x7557e)[0x7fe2bdfa657e] /bin/php-4.3.4(shutdown_memory_manager+0x5f)[0x52a1cf] /bin/php-4.3.4(php_request_shutdown+0x1f6)[0x50f576] /bin/php-4.3.4(main+0x53e)[0x42a1be] /usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7fe2bdf51710] /bin/php-4.3.4[0x42ac79] ======= Memory map: ======== 00400000-00707000 r-xp 00000000 00:00 0 00707000-00907000 ---p 00000000 00:00 0 00907000-00928000 rwxp 00000000 00:00 0 00a00000-00a01000 rwxp 00000000 00:00 0 02007000-020a4000 rwxp 00000000 00:00 0 [heap] 7fe2b8000000-7fe2b8021000 rwxp 00000000 00:00 0 7fe2b8021000-7fe2bc000000 ---p 00000000 00:00 0 7fe2bdaf9000-7fe2bdb0f000 r-xp 00000000 00:13 7782 /usr/lib/libgcc_s.so.1 7fe2bdb0f000-7fe2bdd0e000 ---p 00016000 00:13 7782 /usr/lib/libgcc_s.so.1 7fe2bdd0e000-7fe2bdd0f000 rwxp 00015000 00:13 7782 /usr/lib/libgcc_s.so.1 7fe2bdd1c000-7fe2bdd27000 r-xp 00000000 00:13 7901 /usr/lib/libnss_files-2.23.so 7fe2bdd27000-7fe2bdf26000 ---p 0000b000 00:13 7901 /usr/lib/libnss_files-2.23.so 7fe2bdf26000-7fe2bdf27000 r-xp 0000a000 00:13 7901 /usr/lib/libnss_files-2.23.so 7fe2bdf27000-7fe2bdf28000 rwxp 0000b000 00:13 7901 /usr/lib/libnss_files-2.23.so 7fe2bdf28000-7fe2bdf31000 rwxp 00000000 00:00 0 7fe2bdf31000-7fe2be0c9000 r-xp 00000000 00:13 7737 /usr/lib/libc-2.23.so 7fe2be0c9000-7fe2be2c8000 ---p 00198000 00:13 7737 /usr/lib/libc-2.23.so 7fe2be2c8000-7fe2be2cc000 r-xp 00197000 00:13 7737 /usr/lib/libc-2.23.so 7fe2be2cc000-7fe2be2ce000 rwxp 0019b000 00:13 7737 /usr/lib/libc-2.23.so 7fe2be2ce000-7fe2be2d2000 rwxp 00000000 00:00 0 7fe2be2d2000-7fe2be2e7000 r-xp 00000000 00:13 7896 /usr/lib/libnsl-2.23.so 7fe2be2e7000-7fe2be4e6000 ---p 00015000 00:13 7896 /usr/lib/libnsl-2.23.so 7fe2be4e6000-7fe2be4e7000 r-xp 00014000 00:13 7896 /usr/lib/libnsl-2.23.so 7fe2be4e7000-7fe2be4e8000 rwxp 00015000 00:13 7896 /usr/lib/libnsl-2.23.so 7fe2be4e8000-7fe2be4eb000 rwxp 00000000 00:00 0 7fe2be4eb000-7fe2be4ed000 r-xp 00000000 00:13 7755 /usr/lib/libdl-2.23.so 7fe2be4ed000-7fe2be6ed000 ---p 00002000 00:13 7755 /usr/lib/libdl-2.23.so 7fe2be6ed000-7fe2be6ee000 r-xp 00002000 00:13 7755 /usr/lib/libdl-2.23.so 7fe2be6ee000-7fe2be6ef000 rwxp 00003000 00:13 7755 /usr/lib/libdl-2.23.so 7fe2be6ef000-7fe2be7f2000 r-xp 00000000 00:13 7872 /usr/lib/libm-2.23.so 7fe2be7f2000-7fe2be9f2000 ---p 00103000 00:13 7872 /usr/lib/libm-2.23.so 7fe2be9f2000-7fe2be9f3000 r-xp 00103000 00:13 7872 /usr/lib/libm-2.23.so 7fe2be9f3000-7fe2be9f4000 rwxp 00104000 00:13 7872 /usr/lib/libm-2.23.so 7fe2be9f4000-7fe2bea08000 r-xp 00000000 00:13 7934 /usr/lib/libresolv-2.23.so 7fe2bea08000-7fe2bec07000 ---p 00014000 00:13 7934 /usr/lib/libresolv-2.23.so 7fe2bec07000-7fe2bec08000 r-xp 00013000 00:13 7934 /usr/lib/libresolv-2.23.so 7fe2bec08000-7fe2bec09000 rwxp 00014000 00:13 7934 /usr/lib/libresolv-2.23.so 7fe2bec09000-7fe2bec0c000 rwxp 00000000 00:00 0 7fe2bec0c000-7fe2bec21000 r-xp 00000000 00:13 8008 /usr/lib/libz.so.1.2.8 7fe2bec21000-7fe2bee20000 ---p 00015000 00:13 8008 /usr/lib/libz.so.1.2.8 7fe2bee20000-7fe2bee21000 r-xp 00014000 00:13 8008 /usr/lib/libz.so.1.2.8 7fe2bee21000-7fe2bee22000 rwxp 00015000 00:13 8008 /usr/lib/libz.so.1.2.8 7fe2bee22000-7fe2bee2a000 r-xp 00000000 00:13 7747 /usr/lib/libcrypt-2.23.so 7fe2bee2a000-7fe2bf029000 ---p 00008000 00:13 7747 /usr/lib/libcrypt-2.23.so 7fe2bf029000-7fe2bf02a000 r-xp 00007000 00:13 7747 /usr/lib/libcrypt-2.23.so 7fe2bf02a000-7fe2bf02b000 rwxp 00008000 00:13 7747 /usr/lib/libcrypt-2.23.so 7fe2bf02b000-7fe2bf059000 rwxp 00000000 00:00 0 7fe2bf065000-7fe2bf066000 rwxp 00000000 00:00 0 7fe2bf066000-7fe2bf067000 r-xp 00000000 00:13 1726160 /usr/bin/daemon-preload.so 7fe2bf067000-7fe2bf266000 ---p 00001000 00:13 1726160 /usr/bin/daemon-preload.so 7fe2bf266000-7fe2bf267000 rwxp 00000000 00:13 1726160 /usr/bin/daemon-preload.so 7fe2bf267000-7fe2bf268000 rwxp 00000000 00:00 0 7fe2bf268000-7fe2bf28b000 r-xp 00000000 00:13 7564 /usr/lib/ld-2.23.so 7fe2bf28b000-7fe2bf48b000 ---p 00000000 00:00 0 7fe2bf48b000-7fe2bf48c000 r-xp 00023000 00:13 7564 /usr/lib/ld-2.23.so 7fe2bf48c000-7fe2bf48d000 rwxp 00024000 00:13 7564 /usr/lib/ld-2.23.so 7fe2bf48d000-7fe2bf48e000 rwxp 00000000 00:00 0 7ffc3da7c000-7ffc3da9d000 rwxp 00000000 00:00 0 [stack] 7ffc3db23000-7ffc3db26000 r--p 00000000 00:00 0 [vvar] 7ffc3db26000-7ffc3db28000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Process exited with code 134.
Output for 4.3.3
line1 line1 line3 string(18) "line1 line1 line3 " *** Error in `/bin/php-4.3.3': double free or corruption (fasttop): 0x0000000001bfb730 *** ======= Backtrace: ========= /usr/lib/libc.so.6(+0x6f364)[0x7f9e767cd364] /usr/lib/libc.so.6(+0x74d96)[0x7f9e767d2d96] /usr/lib/libc.so.6(+0x7557e)[0x7f9e767d357e] /bin/php-4.3.3(shutdown_memory_manager+0x5f)[0x514edf] /bin/php-4.3.3(php_request_shutdown+0x1f6)[0x4fa3e6] /bin/php-4.3.3(main+0x53e)[0x4255ce] /usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7f9e7677e710] /bin/php-4.3.3[0x426089] ======= Memory map: ======== 00400000-005d6000 r-xp 00000000 00:00 0 005d6000-007d5000 ---p 00000000 00:00 0 007d5000-007f6000 rwxp 00000000 00:00 0 00800000-00801000 rwxp 00000000 00:00 0 01b82000-01c06000 rwxp 00000000 00:00 0 [heap] 7f9e70000000-7f9e70021000 rwxp 00000000 00:00 0 7f9e70021000-7f9e74000000 ---p 00000000 00:00 0 7f9e76326000-7f9e7633c000 r-xp 00000000 00:13 7782 /usr/lib/libgcc_s.so.1 7f9e7633c000-7f9e7653b000 ---p 00016000 00:13 7782 /usr/lib/libgcc_s.so.1 7f9e7653b000-7f9e7653c000 rwxp 00015000 00:13 7782 /usr/lib/libgcc_s.so.1 7f9e76549000-7f9e76554000 r-xp 00000000 00:13 7901 /usr/lib/libnss_files-2.23.so 7f9e76554000-7f9e76753000 ---p 0000b000 00:13 7901 /usr/lib/libnss_files-2.23.so 7f9e76753000-7f9e76754000 r-xp 0000a000 00:13 7901 /usr/lib/libnss_files-2.23.so 7f9e76754000-7f9e76755000 rwxp 0000b000 00:13 7901 /usr/lib/libnss_files-2.23.so 7f9e76755000-7f9e7675e000 rwxp 00000000 00:00 0 7f9e7675e000-7f9e768f6000 r-xp 00000000 00:13 7737 /usr/lib/libc-2.23.so 7f9e768f6000-7f9e76af5000 ---p 00198000 00:13 7737 /usr/lib/libc-2.23.so 7f9e76af5000-7f9e76af9000 r-xp 00197000 00:13 7737 /usr/lib/libc-2.23.so 7f9e76af9000-7f9e76afb000 rwxp 0019b000 00:13 7737 /usr/lib/libc-2.23.so 7f9e76afb000-7f9e76aff000 rwxp 00000000 00:00 0 7f9e76aff000-7f9e76b14000 r-xp 00000000 00:13 7896 /usr/lib/libnsl-2.23.so 7f9e76b14000-7f9e76d13000 ---p 00015000 00:13 7896 /usr/lib/libnsl-2.23.so 7f9e76d13000-7f9e76d14000 r-xp 00014000 00:13 7896 /usr/lib/libnsl-2.23.so 7f9e76d14000-7f9e76d15000 rwxp 00015000 00:13 7896 /usr/lib/libnsl-2.23.so 7f9e76d15000-7f9e76d18000 rwxp 00000000 00:00 0 7f9e76d18000-7f9e76d1a000 r-xp 00000000 00:13 7755 /usr/lib/libdl-2.23.so 7f9e76d1a000-7f9e76f1a000 ---p 00002000 00:13 7755 /usr/lib/libdl-2.23.so 7f9e76f1a000-7f9e76f1b000 r-xp 00002000 00:13 7755 /usr/lib/libdl-2.23.so 7f9e76f1b000-7f9e76f1c000 rwxp 00003000 00:13 7755 /usr/lib/libdl-2.23.so 7f9e76f1c000-7f9e7701f000 r-xp 00000000 00:13 7872 /usr/lib/libm-2.23.so 7f9e7701f000-7f9e7721f000 ---p 00103000 00:13 7872 /usr/lib/libm-2.23.so 7f9e7721f000-7f9e77220000 r-xp 00103000 00:13 7872 /usr/lib/libm-2.23.so 7f9e77220000-7f9e77221000 rwxp 00104000 00:13 7872 /usr/lib/libm-2.23.so 7f9e77221000-7f9e77235000 r-xp 00000000 00:13 7934 /usr/lib/libresolv-2.23.so 7f9e77235000-7f9e77434000 ---p 00014000 00:13 7934 /usr/lib/libresolv-2.23.so 7f9e77434000-7f9e77435000 r-xp 00013000 00:13 7934 /usr/lib/libresolv-2.23.so 7f9e77435000-7f9e77436000 rwxp 00014000 00:13 7934 /usr/lib/libresolv-2.23.so 7f9e77436000-7f9e77439000 rwxp 00000000 00:00 0 7f9e77439000-7f9e7744e000 r-xp 00000000 00:13 8008 /usr/lib/libz.so.1.2.8 7f9e7744e000-7f9e7764d000 ---p 00015000 00:13 8008 /usr/lib/libz.so.1.2.8 7f9e7764d000-7f9e7764e000 r-xp 00014000 00:13 8008 /usr/lib/libz.so.1.2.8 7f9e7764e000-7f9e7764f000 rwxp 00015000 00:13 8008 /usr/lib/libz.so.1.2.8 7f9e7764f000-7f9e77657000 r-xp 00000000 00:13 7747 /usr/lib/libcrypt-2.23.so 7f9e77657000-7f9e77856000 ---p 00008000 00:13 7747 /usr/lib/libcrypt-2.23.so 7f9e77856000-7f9e77857000 r-xp 00007000 00:13 7747 /usr/lib/libcrypt-2.23.so 7f9e77857000-7f9e77858000 rwxp 00008000 00:13 7747 /usr/lib/libcrypt-2.23.so 7f9e77858000-7f9e77886000 rwxp 00000000 00:00 0 7f9e77892000-7f9e77893000 rwxp 00000000 00:00 0 7f9e77893000-7f9e77894000 r-xp 00000000 00:13 1726160 /usr/bin/daemon-preload.so 7f9e77894000-7f9e77a93000 ---p 00001000 00:13 1726160 /usr/bin/daemon-preload.so 7f9e77a93000-7f9e77a94000 rwxp 00000000 00:13 1726160 /usr/bin/daemon-preload.so 7f9e77a94000-7f9e77a95000 rwxp 00000000 00:00 0 7f9e77a95000-7f9e77ab8000 r-xp 00000000 00:13 7564 /usr/lib/ld-2.23.so 7f9e77ab8000-7f9e77cb8000 ---p 00000000 00:00 0 7f9e77cb8000-7f9e77cb9000 r-xp 00023000 00:13 7564 /usr/lib/ld-2.23.so 7f9e77cb9000-7f9e77cba000 rwxp 00024000 00:13 7564 /usr/lib/ld-2.23.so 7f9e77cba000-7f9e77cbb000 rwxp 00000000 00:00 0 7ffce01a1000-7ffce01c2000 rwxp 00000000 00:00 0 [stack] 7ffce01d1000-7ffce01d4000 r--p 00000000 00:00 0 [vvar] 7ffce01d4000-7ffce01d6000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Process exited with code 134.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: stream_wrapper_register() in /in/5JuZt on line 90