Cheking and error on a PHP function

后端 未结 3 821
甜味超标
甜味超标 2020-12-12 05:11

There is a way to check with a \"IF\" if a function fails in php?

Ex.

If (getimagesize($image) returns and error)  {
ec         


        
3条回答
  •  抹茶落季
    2020-12-12 05:35

    Take a look at exceptions. You'll have to throw them in your function though.

    Edit: By the way, if your function is not supposed to return a boolean, you can always have it return false if something goes wrong and check like:

    $result = getimagesize($image);
    
    if ($result === false)
    {
        //
    }
    

提交回复
热议问题