php returning mixed data types - good or bad

后端 未结 7 685
梦谈多话
梦谈多话 2021-02-02 14:34

When returning values in php, is it considered good or bad practice to return mixed data types. I\'m working on a project where I am constantly faced with methods that return a

7条回答
  •  后悔当初
    2021-02-02 14:59

    I think it is bad practice to return mixed data types. It is possible, as you pointed out, but think about the readability and maintainability of your code. Make sure you comment what you are returning and why, I think that is going to be most important. If you are expecting back an int and you return -1 instead of null, comment that, so you (or someone else) doesn't go crazy trying to figure out what you were trying to do.

提交回复
热议问题