Return Null

  1. Won’t break the app.

  2. Null is equal to “nothing”, so it is expected in the event that a commodity is not found.

  1. End-coder has to manually and OPTIONALLY check for NULL or unexpected, and bad things can happen that won’t be detectable so much until runtime, potentially far away from the function call… Such as, if they try to access $commodiyStore->quantity, the app will crash in a totally non-recoverable “ACCESS PROPERTY ON NON-OBJECT” error, which to the end user will look like a WHITE SCREEN OF DEATH, which is, of course, very bad.
  2. That’s the only con i think of…


Throwing Exception

  1. FORCES the developer to be MINDFUL of his surroundings. First time he tests this and it can’t find the commodity, it IS going to blow up in his face, immediately where he calls the function. So much easier to find.
  2. Impossible to have non-recoverable “access property on non-object” as that future code won’t even be possible to run cuz of the exception.
  3. The end-developer can handle the situation however they want: e.g. assign the value as NULL, throw an error, ask for another commodity, do another action, whatever.
  1. PHP Gurus say “don’t ever throw exceptions for expected potentialities, as they’re not really “exceptional, and besides, Exceptions are bad, mmmmkay?” let me find citation.