1

In one of PHP questions on assessmentee.com, following code:

$a = "";
echo gettype($a);
echo empty($a);
echo is_null($a);
echo isset($x);

returns only "string1"

Why don't we have three bolean values returned, one for each of three functions: empty(), is_null() and isset()?

3
  • 1
    Have you tried to work this out yourself? Commented Nov 28, 2019 at 15:53
  • echo prints to string. false, true, null are not represented as strings, I can't find right now something to share with you explaining it, but you could also use var_dump. Commented Nov 28, 2019 at 16:06
  • yeah, I've tried to get why I'm not getting zeroes for false values Commented Nov 29, 2019 at 16:08

3 Answers 3

5
echo gettype($a);  // outputs "string"
echo empty($a);    // outputs true, in your environment this is 1
echo is_null($a);  // outputs false, "" isn't null, in your environment this is probably blank
echo isset($x);    // outputs false, in your environment this is probably blank
Sign up to request clarification or add additional context in comments.

2 Comments

so, false wil echo as blank? why?
1

You get all the results :string, true, false & false

echo gettype($a);  // outputs "string"
echo empty($a);    // outputs 1 (true)
echo is_null($a);  // outputs false, or "" in echo
echo isset($x);    // outputs false, or "" in echo

Your could try running it this way to see the different resuls:

echo gettype($a),'-',empty($a),'-',is_null($a),'-',isset($x),'-';

output: string-1---

Comments

1
echo gettype($a);  // Outputs a "string" because the datatype used is a string
echo empty($a);    // Outputs true, because the criteria that it is an empty string
echo is_null($a);  // Outputs false, "" isn't null, this is probably blank
echo isset($x);    // Outputs false because isset means "is set"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.