php returning mixed data types - good or bad

后端 未结 7 690
梦谈多话
梦谈多话 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:56

    A function that returns mixed values is not considered bad., in fact thats the beauty of php, it being a dynamic language., so the thing to do is return false on failure and the required value if the function executes correctly,.

    if( false == ( $data = do_something() ) ) return false;
    else print_r( $data );
    

提交回复
热议问题