# Yet another feature request

- Thread: https://externals.io/message/26465
- Original archive: https://news-web.php.net/php.internals/26465
- Started by Arnold Daniels on 2006-11-10T13:26:15+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- 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

---

## #26465 — Arnold Daniels — 2006-11-10T13:26:15+00:00

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

Hi,

I see this is the time to do language feature request. So let me add 
another. I very often use something like:
/$a = isset($x['abc']) ? //$x['abc'] : null;
/This is to prevent an `E_NOTICE` from being thrown.

This subject is already discussed many times, which led to a suggestion 
for PHP6 
(http://www.php.net/~derick/meeting-notes.html#ifsetor-as-replacement-for-foo-isset-foo-foo-something-else)
/$foo = $_GET['foo'] ?: 42;/
This still throws an `E_NOTICE` when the first parameter is not set. Also 
$foo will be set to 42 if the input variable is 0. The conclusion is 
that this feature is useless for the presented situation.

I would like something similar to isset: ifsetor($var, [$default = null]);
/$a = ifsetor($x['abc']);
//$foo = ifsetor($_GET['foo'], 42);
/
I believe adding this feature will remove the biggest con people have on 
working with `E_NOTICE` enabled. I'm sorry if I reopen an already closed 
subject.

Best regards,
Arnold

---

## #26466 — M.Sokolewicz — 2006-11-10T14:34:03+00:00

URL: https://externals.io/message/26465#26466 · In reply to: #26465

read the archives, there's been a LOT of discussion about this already. 
AFAIK the team decided not to implement this before PHP 6.0.

- tul

Arnold Daniels wrote:
> Hi,
> 
> I see this is the time to do language feature request. So let me add 
> another. I very often use something like:
> /$a = isset($x['abc']) ? //$x['abc'] : null;
> /This is to prevent an `E_NOTICE` from being thrown.
> 
> This subject is already discussed many times, which led to a suggestion 
> for PHP6 
> (http://www.php.net/~derick/meeting-notes.html#ifsetor-as-replacement-for-foo-isset-foo-foo-something-else) 
> 
> /$foo = $_GET['foo'] ?: 42;/
> This still throws an `E_NOTICE` when the first parameter is not set. Also 
> $foo will be set to 42 if the input variable is 0. The conclusion is 
> that this feature is useless for the presented situation.
> 
> I would like something similar to isset: ifsetor($var, [$default = null]);
> /$a = ifsetor($x['abc']);
> //$foo = ifsetor($_GET['foo'], 42);
> /
> I believe adding this feature will remove the biggest con people have on 
> working with `E_NOTICE` enabled. I'm sorry if I reopen an already closed 
> subject.
> 
> Best regards,
> Arnold

---

## #26470 — Patrick Mueller — 2006-11-10T15:22:35+00:00

URL: https://externals.io/message/26465#26470 · In reply to: #26465

Arnold Daniels wrote:
> I see this is the time to do language feature request. So let me add 
> another. I very often use something like:
> /$a = isset($x['abc']) ? //$x['abc'] : null;
> /This is to prevent an `E_NOTICE` from being thrown.

It seems to me like adding a function:

    mixed array_get(mixed key, array search [, mixed default_value])

The implementation being:

    // constraint checking here
    if (array_key_exists($key,$search) return $search[$key];
    return $default_value;

would be the way to go.  A functional way to do array access (I don't 
see another way to do this, actually), and also allow a default value if 
  the specified key doesn't exit.

Very similiar to the getProperty() method in Java's Properties class.

-- 
Patrick_Mueller@us.ibm.com
IBM PHP Community Architect, IBM Research Triangle Park
