Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Weird behavior of coalescing operator (??) in php

Can someone please explain, why the results are different in below two cases?

<?php

echo ((7)??0 / (15)??1);

echo "<br><br>";

echo (((7)??0) / ((15)??1));
?>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

See Operator Precedence in the PHP manual.

?? has higher precendance than / so in the first example since 7 is a true value it wins.

In the second example, the parentheses force precedence.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading