J
J
JackShcherbakov2018-01-29 22:12:58
PHP
JackShcherbakov, 2018-01-29 22:12:58

What ?? in php and why is there no information anywhere?

Hello! From David Sklyar's book (page 158) on PHP, I learned about a certain null-join operation. This "miracle" looks like this:
print $a ?? "";
The author says that if you do not insert this thing into the code, then if there is nothing in the variable, then an empty string will be used. And then something is wrong, what the hell are we betting after?? this ""? I thought after ?? you can put your own value to be used, but no! The empty string is always used. So that's not all! If you do not use these questions at all, then there will be no error! It will just output an empty string.
These three lines give the same result for any value of $a:

print $a;
print $a ?? "";
print $a ?? "adsad";

And the strangest thing is that even in the documentation itself (!) I can not find any information about this mysterious contraption.
Maybe the author mixed up programming languages ​​when writing this book?
Thanks in advance!
UPD:
Everything works with the $a variable. But if you take something from the form, then it will not work (for example, №$_POST["name])!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
doublench21, 2018-01-29
@JackShcherbakov

php.net/manual/en/migration70.new-features.php
Null coalescing operator

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question