Does a simple `return` in a PHP function simply end the function prematurely?

前端 未结 5 1675
梦毁少年i
梦毁少年i 2021-02-14 00:43

I have just seen this

// Check to see if the request is a XHR call    
if (request::is_ajax())
{
  // Send the 403 header
  header(\'HTTP/1.1 403 Forbidden\');
          


        
5条回答
  •  逝去的感伤
    2021-02-14 01:33

    function text($var) 
    
    {
    
        if ( ! $var) {
            return;
        }
        do_something();
    
    }
    
    $var = text('');
    
    echo gettype($var);
    echo is_bool($var) ? "true" : "false";
    echo is_string($var) ? "true" : "false";
    echo is_null($var) ? "true" : "false";
    

    returns:

    NULL false false true

提交回复
热议问题