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

后端 未结 8 714
面向向阳花
面向向阳花 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条回答
  •  情深已故
    2021-02-01 19:10

    It depends on the situation and how bad the error is, but a good (and often overlooked) option is to throw an exception:

    getMessage(), "\n";
    }
    

    This will ensure that your function will not fail silently and errors won't go unseen.

提交回复
热议问题