Nicola Pedretti
Nicola Pedretti

Reputation: 5166

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

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?

Upvotes: 4

Views: 610

Answers (1)

tkausl
tkausl

Reputation: 14269

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.

Upvotes: 8

Related Questions