I am now gonna be working on PHP for the next few months. I have been tasked with bringing continuous integration into a set of products that my company is building. Because my last few years I have spent working mostly in java; I decided that before doing any thing about CI in these projects I will spend a few weeks working side by side with the other developers to gain and understanding of PHP as a language and more importantly, the mind set of seasoned PHP developers that have never had any interactions with things like CI, unit testing, continuous deployments and stuff like that.
Today I just got my first PHP project up and going. It is a web app that exposes some rest end points. While getting it up and running I ran into a few problems as any one should expect but it was 1 particular problem that threw me for a loop. I Still can't find an explanation for it and if someone out there can explain it I'll appreciate it.
Here is how it goes. The particular code I was trying to execute was doing nothing; literally nothing, not even giving me an error message. After a few minutes of fiddleing around I got to a point in the code that looked like this:
try{ $this->execute(); } catch (Exception $e){ echo $e; }
So, the execute method was failing. The funny thing is that an error was being generated inside of it and the execution was completely halted; that is, no exception was getting caught in the catch block and the execute method was never returning. Now, I am new to PHP. I have previously worked with java, c#, javascript, c, c++, delphi and a few others I can't remember, and they all had predictable exception handling; so must likely there is something about PHP error handling that I am not quite grasping yet.
The problem turned out to be that I did not have the phpmysqli driver installed.
2 comments:
Many PHP libraries use die() and exit() heavily to prevent further execution of the code. While java, C#, etc are built to be long running applications PHP is the web equivalent of a shell script, targeting short lifetimes and quick execution. Just wait til you get to classes and frameworks that support v4 vs v5 compatibility. ;)
Thanks Nathan.
Stuff like this is making more and more sense to me as I continue to dig into PHP. This particular error doesn't seems to be in any library because it was caused by not having the mysqli library installed. So instead it was the PHP runtime that decided to die() or exit() when unable to resolve a dependency event when the offending statement was inside a try catch block.
Post a Comment