Why I love/hate PHP
But for all its foibles, it’s still, in my opinion, one of the best ways to rapidly get a web application up and running. Historically, it has been loosely typed, and once you have Apache and PHP installed, you’re good to go, there are no other frameworks to install, no IDE or compiler is strictly needed, etc. Easy.
So not only have I used it here and there, I’ve taken some pains to reinvent certain wheels to make it even easier. (E.g., I rescued PHPHTMLTemplate (itself a port of the Perl module HTML::Template), implemented a PHP approximation of CGI::Application, and have written at least most of a database abstraction layer “inspired by” Class::DBI.) And I’ve written some of my own personal use apps in those frameworks.
Everything was running fat, dumb, and happy on PHP 7.3, but PHP (like Python, albeit maybe to a lesser extent) loves to break things. And if you’re a hobbyist, you may not be up on all the changes.
In PHP5, there are two ways you can write a constructor method inside a class. The first one is to create a method with the name __construct() inside the class. The second is to create a method naming exactly the same as class name. For example if your class name is Emailer, the name of the constructor method will be Emailer().
Hayder, Hasin, Object-Oriented Programming with PHP5 (Packt Publishing Ltd., 2007), p. 24.
I’ve always used __construct() (and getters and setters, vs. dynamically sticking attributes onto an object in running code), but the original author of the PHPHTMLTemplate code used the “class name” method. And when I upgraded my system from 7.3 to 8.2 to fix a different dependency, everything broke. It took me a minute to figure out why. There were no warnings about the deprecated nomenclature, just code weirdness where objects were null when they should have been instances of a class. There were a number of other tweaks I had to make to the inherited codebase, which is now cleaner and more robust, in my opinion (functions are no longer being called with null values when the don't need to be, dynamic properties are no longer being used, etc). But it was a bit frustrating when suddenly nothing worked.
Yes, I should have setup a beta or test environment and done regression testing before making the change to the underlying software. Maybe I should dockerize everything and have interchangeable server environments, so dropping back to 7.3 from 8.2 could have been done in situ. Etc. All valid points that I thought about after the fact, since this stuff is, again, a hobby, not a vocation. But, well, yeah.
‡ It’s great software, I just think it’s a bit expensive for a hobbyist like me, at $99 for an individual (though that at least reverts to a “perpetual license” at the end of the year), with no free version for open source contributors, etc. (they offer that for some of their products).
Comments
Post a Comment