Compile: Add more php_shrink tests

This commit is contained in:
Jakub Vrana
2025-03-12 23:32:34 +01:00
parent 818b9ad903
commit b9b4db0c8e
2 changed files with 26 additions and 3 deletions

View File

@@ -1,7 +1,18 @@
<?php
// based on http://latrine.dgx.cz/jak-zredukovat-php-skripty
/** Minify PHP code with these operations:
* remove extra {}
* minify variables
* strip comments, preserve only the first doc-comment
* join consecutive echo
* change ?>HTML<?php to echo 'HTML' if it saves space
* strip public visibility or change it to var
*
* @param string PHP code including <?php
* @return string
*/
function php_shrink($input) {
// based on http://latrine.dgx.cz/jak-zredukovat-php-skripty
$special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER', '$http_response_header', '$php_errormsg'));
$short_variables = array();
$shortening = true;