Search code examples
phpreturnreturn-type

PHP class method return type


Is it possible to define the return type like this?

public static function bool Test($value)
{
      return $value; //this value will be bool
}

Solution

  • As per this page : http://php.net/manual/en/language.types.type-juggling.php

    You can try doing,

    return (boolean) $value;
    

    Now PHP offer return type declaration from PHP 7. I have explained how to use return type in PHP