3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function minimize($file) { return preg_replace('#(<\?php)\s+#S','$1 ',preg_replace('#\s*([(){}[\];,.:+<>*/%^=&?|$-])\s*#S', '$1', array_reduce(token_get_all(php_strip_whitespace($file)),function($c,$x){ static $s = [], $i=0; if ( is_string($x) ) return $c . $x; $_ = $x[1]; switch($x[0]){ case T_STRING: return $c . (defined($_) ? (is_bool($k=constant($_))||is_null($k)?$_:$k) : $_); case T_VARIABLE: return $c . (empty($s[$_]) ? ($s[$_] = '$_' . base_convert($i++,10,36)) : $s[$_]); case T_LOGICAL_OR: return $c . '||'; case T_LOGICAL_AND: return $c . '&&'; default: return $c . $_; } }))); } echo minimize(__FILE__);
based on 4f0Gi
Output for 7.0.0 - 7.1.0
<?php function minimize($_0){return preg_replace('#(<\?php)\s+#S','$1 ',preg_replace('#\s*([(){}[\];,.:+<>*/%^=&?|$-])\s*#S','$1',array_reduce(token_get_all(php_strip_whitespace($_0)),function($_1,$_2){static$_3=[],$_4=0;if(is_string($_2))return$_1.$_2;$_5=$_2[1];switch($_2[0]){case 319:return$_1.(defined($_5)?(is_bool($_6=constant($_5))||is_null($_6)?$_5:$_6):$_5);case 320:return$_1.(empty($_3[$_5])?($_3[$_5]='$_'.base_convert($_4++,10,36)):$_3[$_5]);case 263:return$_1.'||';case 265:return$_1.'&&';default:return$_1.$_5;}})));}echo minimize(__FILE__);
Output for 5.4.0 - 5.4.45, hhvm-3.10.0 - 3.12.0
<?php function minimize($_0){return preg_replace('#(<\?php)\s+#S','$1 ',preg_replace('#\s*([(){}[\];,.:+<>*/%^=&?|$-])\s*#S','$1',array_reduce(token_get_all(php_strip_whitespace($_0)),function($_1,$_2){static$_3=[],$_4=0;if(is_string($_2))return$_1.$_2;$_5=$_2[1];switch($_2[0]){case 307:return$_1.(defined($_5)?(is_bool($_6=constant($_5))||is_null($_6)?$_5:$_6):$_5);case 309:return$_1.(empty($_3[$_5])?($_3[$_5]='$_'.base_convert($_4++,10,36)):$_3[$_5]);case 263:return$_1.'||';case 265:return$_1.'&&';default:return$_1.$_5;}})));}echo minimize(__FILE__);
Output for 5.6.0 - 5.6.28
<?php function minimize($_0){return preg_replace('#(<\?php)\s+#S','$1 ',preg_replace('#\s*([(){}[\];,.:+<>*/%^=&?|$-])\s*#S','$1',array_reduce(token_get_all(php_strip_whitespace($_0)),function($_1,$_2){static$_3=[],$_4=0;if(is_string($_2))return$_1.$_2;$_5=$_2[1];switch($_2[0]){case 310:return$_1.(defined($_5)?(is_bool($_6=constant($_5))||is_null($_6)?$_5:$_6):$_5);case 312:return$_1.(empty($_3[$_5])?($_3[$_5]='$_'.base_convert($_4++,10,36)):$_3[$_5]);case 263:return$_1.'||';case 265:return$_1.'&&';default:return$_1.$_5;}})));}echo minimize(__FILE__);
Output for 5.5.0 - 5.5.38
<?php function minimize($_0){return preg_replace('#(<\?php)\s+#S','$1 ',preg_replace('#\s*([(){}[\];,.:+<>*/%^=&?|$-])\s*#S','$1',array_reduce(token_get_all(php_strip_whitespace($_0)),function($_1,$_2){static$_3=[],$_4=0;if(is_string($_2))return$_1.$_2;$_5=$_2[1];switch($_2[0]){case 308:return$_1.(defined($_5)?(is_bool($_6=constant($_5))||is_null($_6)?$_5:$_6):$_5);case 310:return$_1.(empty($_3[$_5])?($_3[$_5]='$_'.base_convert($_4++,10,36)):$_3[$_5]);case 263:return$_1.'||';case 265:return$_1.'&&';default:return$_1.$_5;}})));}echo minimize(__FILE__);
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/pvOcX on line 6
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/pvOcX on line 5
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_FUNCTION in /in/pvOcX on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/pvOcX on line 5
Process exited with code 255.