Saturday 11 February 2023

PHP 8 : leaving freedom behind for dummies .. or the version that killed PHP 🤦‍♂️

 As many developers running big production projects ..  I'm a faithful believer on two concepts : KISS & if it ain't broke don't fix it.

So .. being the late adopter that I'am and given the complexity involved in most "major version" upgrades due to backward incompatibilities and deprecated functions (for no good reason) .. I recently turned my eye into PHP 8 .. why now? well basically a Wordpress plugin kindly reminded me about upgrading .. so why not? right? off we go ...

Set everything up .. read about it .. decide which version to upgrade to .. download .. ./configure AND stop .. first bump .. a few options are no more .. a few others have actually changed from --enable to --with and viceversa .. really? seems completely stupid thing to do .. but hey! it's the new PHP must be worth it! .. pass that bump .. compile .. install .. NO PEAR .. bump .. redo --with-pear (although not properly documented) .. 'cause one must assume for  Thies C. Arntzen, Stig Bakken, Shane Caraveo, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski it must be much more fun to rebuild all those extensions from scratch right? .... 


Anyhow .. I'm past the install process and now to check our test unit .. WARNING WARNING WARNING !!!! FATALITY ... our first typecasting issue arises : substr("3XYZ",0,1)-1can no longer be understood ... wait .. what? .. that can't be .. PHP IS SMART !! (well at least used to be) .. that's one of the VERY FEW PERKS of still working with PHP : typejuggling (string)"3" - (int)1 = (int)2 because PHP KNEW that an arithmetical operator implied a numeric context ... but noooo ... now the PHP geniuses decided that there is no way that "3"-1 can be interpreted as =2 and now they REQUIRE US to typecast thousands of lines of code OR decide not to upgrade at all because for some reason they were unable to make this a WARNING .. a feature that has been used since PHP was conceived is now not just a bug but a FATAL ERROR that will not allow your code to run at all.


So .. anyways .. lets jump over this hoop and see what other errors may lurk beyond this typecasting UTTER NONSENSE .. and let me be clear .. they could've made this a WARNING or a NOTICE .. but they decided to make this a FATAL ERROR .. no wonder why only 3% of PHP users worldwide have adopted it .. most if not all major production projects won't typecast thousands of lines of code.


On our test unit I decided to clean up the code and leave just tiny part & fix the errors to find out if that was that .. LOL .. hell no .. guess what .. arrays!! .. another one of the most basic structures of any project : asort now throws a FATAL ERROR:


[PHP8] TypeError : asort(): Argument #1 ($array) must be of type array, null given.


!!! regardless of using an error supression operator @ !!!!


Obviously this error applies to any function that deals with arrays not just the sorting family .. weeeell that was that for me .. if this was a simple taste of what will need to be done to hundreds of files and  hundreds of thousands of lines of code .. I will not even try to figure what comes after that.. nope. 


I will be recommending going a different a path and implementing a different language altogether given the need to basically recode everything .. then let's recode on a more futureproof language that will hopefully not force it's users to recode everything on a whim from a bunch of people just to add a few additional features that definitely do not make for what they brake : dumb union types + JIT vs years and years of lines of code and coding paradigms.


No wonder Wordpress has begun shifting all their code to NodeJS and Microsoft decided NOT TO SUPPORT PHP8 in any way. Turning PHP into Java or anyother close minded squared nonsensical language that requires the coder to code more instead of less is a BIG no-no, it simply IS NOT THE WAY.