Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does isset not throw an error when evaluating array properties?

Tags:

php

isset

Whenever I try to access a property of an array that does not exist, php throws an ERROR_NOTICE that reads like this:

Notice: Undefined offset: BLANK in BLANK on line BLANK

$a = array("a","b","c");

$a[4]; //throws an error

Instead, if I use isset to test for the existence of this property, this error is not thrown.

$a = array("a","b","c");

isset($a[4]); //does not throw an error

Since php does evaluate arguments before passing them to a function, how does isset avoid to throw an error?

like image 755
Nicola Pedretti Avatar asked Oct 20 '25 12:10

Nicola Pedretti


1 Answers

isset isn't a function but a language construct:

Note: Because this is a language construct and not a function, it cannot be called using variable functions.

It's not called the way functions are called but handled specially by the language. The same goes for empty.

like image 79
tkausl Avatar answered Oct 22 '25 01:10

tkausl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!