It seems like my code works to check for null if I do
if ($tx)
or
if (isset($tx))
why would I do the se
These two are quite different, as every single answer has pointed out. If you do not use isset, many things will evaluate to false, especially arrays, values of false, numeric values of 0 (and others), etc. True that.
It seems strange to me that everyone is so quick to defend correct programming in PHP. If I want to do correct programming, I've got tons of statically-typed, strongly-typed languages to do it with. It seems to me that one advantage to PHP is that I don't have to think about types that much. Sure, there are cases where
if ($tx)
evaluates to false when it in fact does have a value, but if you want to check if it's a Transaction Object or not, it either works or it doesn't. It turns out that, with the Doctrine framework, this code
if (isset($tx))
always evaluates to true after grabbing the first object of a query. I instead have to say
if ($tx instanceof PurchaseRecord)
So my point is that in PHP, you know what you're testing for! For instance, if it's a parameter from a GET request, it will either be null, empty, or have a value. You must handle these three cases. Or two cases, or whatever number of cases you have in your particular code. Once you have, if it works on your development server and it works on your production server, maybe you can say that it works and get on with your life?
(In Java or C#, it has to compile and then run without throwing Exceptions. Most NullPointer exceptions in Java actually get thrown with no problems being caused: Java APIs cannot possibly check for all nulls in code because it's impossible, and also because it's no problem. If it compiles and works when it's supposed to, you know your code is okay. Then later you can worry about throwing more correct Exceptions.)
If at all points you have to know what the underlying types of your code in PHP, why not code using types in the first place? Or more to the point, why not take advantage of the looseness of PHP and code with code that runs.