Skip to content
Advertisement

Tag: try-catch

How to catch a fatal error both in PHP 7 and 8?

I have a PHP 7 script, that basically does this: To be clear: if the class I am looking for is “Main” and can’t be found, I must display the text, else it’s supposed to throw the exception anyway. It works well with PHP 7, but PHP 8 does not catch the error. Instead, it shows: How am I supposed

php try catch not working properly

I have code like this: and problem is that, when file_get_contents can not read url (may be site not responding or something like this..) my code writes error: failed to open stream: HTTP request failed! and execution goes direct to finally block bypass catch block without entering in it.. any ideas? Answer You can set an empty error handler to

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