Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: not "autovivification", but ...?

5 views
Skip to first unread message

Thomas 'PointedEars' Lahn

unread,
Jun 1, 2016, 8:16:49 PM6/1/16
to
Stefan Weiss wrote:

> PS, a little off-topic: PHP is probably the worst language to work with in
> this regard. It will happily allow implicit multi-level creation in arrays
> -
>
> // ($foo is unused up to this point)
> $foo["bar"][13]["baz"] = "qux";

This is so very useful. (No sarcasm.)

> - but will emit E_NOTICE (a type of error)

A common misonception. It is a kind of debug message instead and can be
suppressed in various ways.

> if we try to read a nonexistent index ($foo["x"]).
^^^^^
The proper term is _key_, and if you write

@$foo["x"]

the notice will go away without any extra configuration.

F'up2 comp.lang.php

--
PointedEars (ZCE PHP)
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

Christoph M. Becker

unread,
Jun 2, 2016, 5:47:07 AM6/2/16
to
On 02.06.2016 at 02:16, Thomas 'PointedEars' Lahn wrote:

> Stefan Weiss wrote:
>
>> PS, a little off-topic: PHP is probably the worst language to work with in
>> this regard. It will happily allow implicit multi-level creation in arrays
>> -
>>
>> // ($foo is unused up to this point)
>> $foo["bar"][13]["baz"] = "qux";
>
> This is so very useful. (No sarcasm.)
>
>> - but will emit E_NOTICE (a type of error)
>
> A common misonception. It is a kind of debug message instead and can be
> suppressed in various ways.
>
>> if we try to read a nonexistent index ($foo["x"]).
> ^^^^^
> The proper term is _key_, and if you write
>
> @$foo["x"]
>
> the notice will go away without any extra configuration.

As well as all other notices, warnings, etc. Not a problem in this
case, but consider:

function keyName() {
trigger_error('deprecated', E_USER_DEPRECATED);
return 'x';
}
@$foo[keyName()];

--
Christoph M. Becker

Thomas 'PointedEars' Lahn

unread,
Jun 3, 2016, 4:20:36 PM6/3/16
to
Straw man (Stefan in cljs, *and* you, being more courteous than him, here
where it belongs).

I did not say it were the best solution. I did not say it were a general
solution. I said it is *a* solution *without extra configuration*.

See also: <http://php.net/error_reporting>

--
PointedEars
Zend Certified PHP Engineer
<http://www.zend.com/en/yellow-pages/ZEND024953> | Twitter: @PointedEars2

Christoph M. Becker

unread,
Jun 4, 2016, 10:24:02 AM6/4/16
to
On 03.06.2016 at 22:20, Thomas 'PointedEars' Lahn wrote:

> Christoph M. Becker wrote:
>
>> As well as all other notices, warnings, etc. Not a problem in this
>> case, but consider:
>>
>> function keyName() {
>> trigger_error('deprecated', E_USER_DEPRECATED);
>> return 'x';
>> }
>> @$foo[keyName()];
>
> Straw man (Stefan in cljs, *and* you, being more courteous than him, here
> where it belongs).
>
> I did not say it were the best solution. I did not say it were a general
> solution. I said it is *a* solution *without extra configuration*.

And I merely stated that this solution might have drawbacks in more
complex cases. I understand that you already have been aware of these
dangers, but not necessarily other readers.

--
Christoph M. Becker
0 new messages