# RFC: Allow arbitrary expression arguments to empty() and isset()

- Status: Implemented (PHP 5.5)
- Authors: Nikita Popov nikic@php.net
- Date: 2012-04-12
- Original: https://wiki.php.net/rfc/empty_isset_exprs
- Page: https://externals.io/rfc/empty_isset_exprs
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Votes

### Which of the language constructs should accept arbitrary arguments? (closed)

Both empty() and isset(): 3 · Only empty(): 14 · None: 4

Voters: ab (Only empty()), brianlmoon (Both empty() and isset()), cataphract (None), colder (Only empty()), dragoonis (Only empty()), drak (Only empty()), hholzgra (Only empty()), hradtke (None), ircmaxell (Both empty() and isset()), kassner (Only empty()), lstrojny (Only empty()), lynch (None), mfonda (Only empty()), mj (Only empty()), nikic (Only empty()), pajoye (Only empty()), patrickallaert (Only empty()), rdohms (Only empty()), salathe (None), stas (Both empty() and isset()), weierophinney (Only empty())

### Should empty() and isset() accept arbitrary arguments? (closed)

yes: 12 · no: 2

Voters: cataphract (yes), colder (yes), ircmaxell (yes), kassner (yes), kriscraig (yes), laruence (yes), mike (yes), mj (yes), neufeind (yes), nikic (yes), patrickallaert (no), salathe (no), stas (yes), tyrael (yes)

## Discussions on the mailing list

- [\[RFC\] Allow non-variable arguments to empty() and isset()](https://externals.io/message/59804.md) — started on 2012-04-12, 30 messages
- [\[VOTE\] Allow non-variable arguments to empty()](https://externals.io/message/60206.md) — started on 2012-04-18, 9 messages
- [\[VOTE\] Vote change for empty() RFC](https://externals.io/message/60395.md) — started on 2012-05-01, 43 messages

---

### Summary

This RFC proposes to allow **arbitrary expressions** as arguments to `empty()` and `isset()`.

### What is the current behavior?

Currently `empty()` and `isset()` only accept variables as arguments. Thus it is possible to write `empty($foo)`, but it is not possible to write `empty(foo())`.

Trying to do so results in this not particularly helpful error message: “Can't use function return value in write context”.

For other expressions (not variables and not function calls) a parse error is thrown.

### Why was this behavior chosen in the past?

Using `empty()` and `isset()` on a non-variable was disallowed previously, as the main purpose of these language constructs is to suppress an error message in case the passed variable does not exist.

As for function calls (and other expressions) it is already known that the value exists, using `empty()`/`isset()` is not necessary and `!func()`/`func() !== null` can be used instead.

### Why should we change the behavior?

Even though `!func()` and `empty(func())` would behave exactly the same, the latter is more readable in certain contexts. For example if `func()` is expected to return an array, it feels more natural to verify it's emptiness using `empty()` instead of `!`.

Furthermore the current behavior often is unexpected to newbies. `empty()` and `isset()` look like functions, so programmers new to PHP expect them to accept any value (in particular function call results).

### Patch

The patch is available as a PR on Github: <https://github.com/php/php-src/pull/54>

### Change only empty()?

After further discussion it seems like it might be better to only add expression support for `empty()`, but not for `isset()`. The original RFC included `isset()`, because changing only one of the language constructs seemed inconsistent (as they are so similar).

On the other hand, using `isset()` on function calls and other expressions doesn't seem particularly useful. `isset(someFunction())`is semantically unclear (how can `someFunction()` not be set?) and could be interpreted as a check whether the function itself exists.

Allowing `isset()` to accept expressions would probably only cause confusion.

### Vote

**Vote: Which of the language constructs should accept arbitrary arguments?** — Both empty() and isset(): 3 · Only empty(): 14 · None: 4 (closed)

The previous vote is obsolete and is left here only for reference:

**Vote: Should empty() and isset() accept arbitrary arguments?** — yes: 12 · no: 2 (closed)

### Result

The RFC was accepted with the option “Only empty()”. The relevant commit it <https://github.com/php/php-src/commit/ec061a93c53c8cde10237741e98e992c1a05d148>.
