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

后端 未结 5 1053
不知归路
不知归路 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:34

    You need to use class_exists to see if the class exists before you try and instantiate it.

    Incidentally, if you're using a class autoloader, be sure to set the second arg to true.

提交回复
热议问题