The command echo does not return anything. But print returns 1. Always. What is the practical use of this returning 1? Sure it can be used in an expression, but isn't the expression useless if it is always true and cause use of more code?
<?php
unset($empty);
if(print ($empty)){
echo "Yep sure thing. Print strikes again with a ", "1.";
}
?>
Shouldn't it always return the same result as below, so what's the point then?
<?php
print ($empty);
echo "Yep sure thing. Print strikes again with a ", "1.";
?>
This question is about the returning 1 and not that "Echo allows echoing more than one string separated by commas while print doesn't" etc.
print
always returns one in the real world. If you are trying to perform Inception, you can devise a print
function that always returns zero. That way, you can check to see if you are in a dream or the real world.
In reality however, the usage of print
's return value is the same as simply using true
. Infinite while loops, printing debugging information, etc. are all very compelling uses but they are bad design (verging on insane) and should be avoided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With