# [proposal+patch] Addition of ?() as shorthand for isset()

- Thread: https://externals.io/message/62030
- Original archive: https://news-web.php.net/php.internals/62030
- Started by Andrew Faulds on 2012-08-04T00:54:00+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #62030 — Andrew Faulds — 2012-08-04T00:54:00+00:00

URL: https://externals.io/message/62030#62030

Hi!

I've always thought isset() was quite ugly. For something I use quite 
frequently for checking the existence of array keys, I feel it is too 
many keystrokes, and is ugly.

So, I decided I would create a shorthand for isset().

One option suggested was a new operator, 'expr ??', which I don't like 
the idea of very much. I would also have liked 'expr ?', but that would 
conflict with the ternary operator, 'expr ? expr : expr'. Then, I had 
the idea of '? expr', but that also caused a conflict. So I settled on 
'? ( expr )', which is used like this:

   if (?($_POST['credit_card_no'])) {
       // ...
   } else if (!?($_POST['use_paypal']) && ?($_POST['bank_acc_no'])) {
       // ...
   }

And since it doesn't break the ternary operator, like this:

   $number = ?($x)? intval($x) : 0;

I quite like how it combines with !, so !?() tests for non-existence, 
and ?() tests for existence.

It's quite trivial, but it would save me (and probably many others) 
time, and I think it would add some extra character to PHP, with its 
quirky syntax. :)

Patch attached. Thoughts welcome.

-- 
Andrew Faulds
http://ajf.me/
