# Implicit isset in ternary operator

- Thread: https://externals.io/message/61960
- Original archive: https://news-web.php.net/php.internals/61960
- Started by Andrew Faulds on 2012-08-02T10:54:04+00:00
- Messages: 3
- 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

---

## #61960 — Andrew Faulds — 2012-08-02T10:54:04+00:00

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

Hi,

Also in JavaScript if in strict mode. Legacy non-strict mode JS doesn't cause an error though.

JS's || operator supresses this error though, which is great for e.g. x = x || new Object();

--
Sent from Samsung Mobile
Andrew Faulds
http://ajf.me/

Stas Malyshev <smalyshev@sugarcrm.com> wrote:

Hi!

> I've looked a bit into other languages (Ruby, Python, Go) and
> all of them do not generate an error when an undefined dict/hash/map key is accessed.

Python would definitely throw an exception:

> > […]
{}
> > […]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'a'

And it's just as annoying as in PHP. Actually, probably more annoying
:). But it has .get() which solves the problem usually, albeit in a bit
more verbose way. Also, Python has defaultdict which I would usually use
when I need keys to be created automatically.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

---

## #61975 — Alex Aulbach — 2012-08-02T22:26:35+00:00

URL: https://externals.io/message/61960#61975 · In reply to: #61960

2012/8/2 Andrew Faulds <ajf@ajf.me>:
> Hi,
>
> Also in JavaScript if in strict mode. Legacy non-strict mode JS doesn't cause an error though.
>
> JS's || operator supresses this error though, which is great for e.g. x = x || new Object();

Could be cool to make this in PHP with the 'or' operator (or not ||)...
Which brings us back to the subject...

-- 
Alex Aulbach

---

## #62461 — Ferenc Kovacs — 2012-08-24T21:15:30+00:00

URL: https://externals.io/message/61960#62461 · In reply to: #61975

On Fri, Aug 3, 2012 at 12:26 AM, Alex Aulbach <alex.aulbach@gmail.com>wrote:

> 2012/8/2 Andrew Faulds <ajf@ajf.me>:
> > […]
> cause an error though.
> > […]
> = x || new Object();
>
> Could be cool to make this in PHP with the 'or' operator (or not ||)...
> Which brings us back to the subject...
>
> --
> Alex Aulbach
>
> --
> 
> 
>
>
most/some of the ideas here were brought up before, there is a proposal and
a nice history of mailing list discussions (albeit not up-to-date) at
https://wiki.php.net/rfc/ifsetor
personally I would really like an ifsetor/coelesce kind of language
construct.
accepts any number of arguments, won't trigger notice on unset variables,
and returns the first non-null argument.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu
