I'm am embarking into the world of template systems ( turns out Conditionals are incredibly easy to do... ), and one of the things I'd like to try is a light PHP optimizer. I'm not talking about an accelerator, but a PHP script which optimized PHP files directly.
So what is considered 'faster' with PHP? So far I have (guessing)
- Remove all comments (human conveniences)
- Remove all ' ', '\t', '\n' (human conveniences)
- Preferably use ' over " with strings. (PHP ignores ')
- Rename all variables and functions to shortest possible, aa, ab .. ZQ (from C++)
- Replace == with ===, != with !==, etc. (from Javascript)
- If 1 line If-Then-Else, remove brackets (not sure)
- Recycle variables wherever possible. (hard)
- Replace all $var++ and $var-- with ++$var, --$var.
- Replace strlen checks with isset($var{length})
I am guessing embing user-functions directly into the code is actually slower for PHP as it has to compile. Please remember I am a nub.