1

While writing a function to sanitize a configuration array, I noticed that it is not possible to call unset after &&.Now I'm curious. What is the difference between unset and the call of any other function? For example, the first short-if is completely valid the second one will throw a parser exception.

<?php

$a = ['test' => 1];

isset($a['test']) && test();
isset($a['test']) && unset($a['test']) ;

function test(){
    return 123;
}
David P.
  • 370
  • 1
  • 13
  • 1
    Perhaps more information on https://stackoverflow.com/questions/10476028/is-this-special-treatment-of-exit-and-die-documented-in-phpm especially the part about *Here are the interesting few which do not return a value, and therefore are not expressions*. – Nigel Ren Jun 03 '20 at 10:49
  • 1
    Thx for digging up this post. This is very interesting and does indeed answer my question. – David P. Jun 03 '20 at 10:53

0 Answers0