Why doesn't PHP catch a “Class not found” error?

后端 未结 5 1093
不知归路
不知归路 2020-12-30 20:20

In the following example, if the class does not exist, I want to catch the error and create a Null class instead.

But in spite of my try/catch statement

5条回答
  •  没有蜡笔的小新
    2020-12-30 20:52

    Because it's a fatal error. Use class_exists() function to check if class exist.

    Also: PHP is not Java - unless you redefined default error handler, it will raise errors and not throw exceptions.

提交回复
热议问题