[ACCEPTED]-what does a php function return by default?-language-design
Accepted answer
null
null
if(foo() === null)
- -
- Nope.
You can try it out by doing:
$x = foo();
var_dump($x);
0
Not returning a value from a PHP function 5 has the same semantics as a function which 4 returns null.
function foo() {}
$x=foo();
echo gettype($x)."\n";
echo isset($x)?"true\n":"false\n";
echo is_null($x)?"true\n":"false\n";
This will output
NULL
false
true
You get the 3 same result if foo is replaced with
function foo() {return null;}
There 2 has been no change in this behaviour from 1 php4 to php5 to php7 (I just tested to be sure!)
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.