In php, should I return false, null, or an empty array in a method that would usually return an array?

后端 未结 8 603
面向向阳花
面向向阳花 2021-02-01 18:22

I\'ve found several responses to this, but none pertaining to PHP (which is an extremely weak typed language):

With regards to PHP, is it appropriate to return

8条回答
  •  猫巷女王i
    2021-02-01 19:00

    I assume that the return type of your method is array, so you should return an empty array only if the execution went fine but no results were found.

    In case of an error, you should throw an exception. This should be the preferred way to handle errors.

提交回复
热议问题