Skip to content
Advertisement

Tag: exception-handling

Why isn’t my PHP exception working?

I am new to exceptions in PHP or any language really. I am trying to catch an exception if a user enters an invalid textual timezone (“xxxxxxxxxx” in this case). My test case is definitely invalid as an exception is triggered, just not the catch logic which is supposed to handle it intelligently. Basically I want it to use a

PHP variable scope within Try/Catch block

In PHP, how do variable scope rules apply to Try/Catch blocks? Do variables declared within the try block go out of scope when the block has finished? Or are they in scope until the end of the function/method? For example: Is this valid? Or should $o = NULL; be set before the try/catch to keep $o in scope? (I know

Advertisement