Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy. This forum is not for asking programming related questions.
Just curious whether anyone has ever discovered a need to backtrack a PHP5 application/class down to PHP4 compliance and found a decent method to automate the process given the PHP5 code is not so dependent on PHP5 features as to make this impossible.
Maybe I'm insane, but I've tired of sticking with PHP4, and am moving to PHP5 for several projects. The uncertain goal is to enable a largely autmated process to convert the PHP5 code into PHP4 friendly forms. I'm thinking it would involve file rewriting (replacing PHP5 syntax with PHP4), extracting PHP5 dependent code into independent classes or simply keeping PHP4/5 variants of the class on hold, and having a possible separate tree of file writing rules (maybe a bit like phpBB module system for changing core files).
Am I completely off my rocker?
The motivation for retaining PHP4 as an option is that the majority of users on shared hosting are likely to require the fallback. In the meantime I prefer coding in PHP5 and enjoying type casting and private/public declarations that make debugging and interface enforcement a much more pleasant experience. As well as avoiding some fuzzy logic since PHP4's class properties might as well be globals...
The way I planned on doing my own fallback code was to use the built-in tokenizer in 5 to read the code for all the files and rewrite most of them right there. The majority of added functions in 5 are available in compatibility versions through pear and whatnot. As for more sticky bits like the magical functions in classes, I was going to map them in some fashion. After further thinking, instead of relying on 5's magical calls I was just going to make literal calls to most of them (converted from automagic to standard calls) .. anyway, that was my idea.. haven't tried it.
Steps to blissful PHP5/4 coexistance while coding:
1. Code using PHP4-available commands
2. When #1 fails, find or write PHP4-compatible replacements for PHP5 commands you need
3. When #1 and #2 fails, return to #1.
As to automated? No such joy. There is however, http://pear.php.net/package/PHP_Compat , which does the same as the above in most cases. Its pretty useful, with the caveat that the license it is under (the PHP License) is not compatible with the GPL or the Affero GPL. I'm not bitter, really.
Until Cpanel and Plesk make PHP5+ the default, I'm stuck on PHP4, so I feel your pain.
Step 1 is the problem - I don't particularly want to. . Typically I'd like to use PHP5 class constants, type hinting, private/public properties, and use these as the basis for the overall design and tests (where such things seal up the behaviour of a class). Then drop back to PHP4 as easily as possible from there (replacing the PHP5 declaration/type hints/etc. I know there'll be some manual work involved - most of it once off thankfully, but automating this even a little would save a lot of time spent editing classes.
Also I know I don't have the patience for such editing so I'll inevitably leave bugs behind....
Maugrim_The_Reaper wrote:Step 1 is the problem - I don't particularly want to. . Typically I'd like to use PHP5 class constants, type hinting, private/public properties, and use these as the basis for the overall design and tests (where such things seal up the behaviour of a class).
You're in the same boat as me.
Take Swift, at the moment the way I'm developing is that I do it the way "i like it" in PHP5, using PHP5 standards but not strictly using anything that doesn't exist in PHP4. Before I relase a new version I take my PHP5 code and literally go through it by hand replacing all public, private keywords with var and removing them from methods all together. I also change the name of the constructor and that's it. Quick test just to make sure I haven't missed something and it's packaged up with "-php4" appended to the version.
It's a pain but I'd seriosuly rather have two running versions than have a halfway house between the two. What's the point in using PHP5 if you don't make use of the enhanced OOP features?