Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "isset($a[0]) and unset($a[0]);" cause syntax error?

Tags:

php

unset

My Code:

$a = [];
isset($a[0]) and unset($a[0]);

it shows "syntax error, unexpected 'unset' (T_UNSET)"

but

$a = [];
isset($a[0]) and exit();

it works!

Both of exit() and unset() are returning no value. Why does one work but not the other?

like image 869
yrssoft Avatar asked Oct 19 '22 09:10

yrssoft


1 Answers

unset is a language construct, not a real function (this is why you get T_UNSET and not a more generic term), so it doesn't play by the same rules as a normal function would. isset and exit are also language constructs, but they behave more like normal functions.

like image 72
Austin Avatar answered Oct 22 '22 01:10

Austin