3v4l.org

run code in 200+ 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

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Output for Typed properties v2
<?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 Array change keys
<?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 Lexical anon
<?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 317:return$_1.(defined($_5)?(is_bool($_6=constant($_5))||is_null($_6)?$_5:$_6):$_5);case 318: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__);

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page