On Sat, Jan 15, 2011 at 1:51 AM, la...@garfieldtech.com
<la...@garfieldtech.com> wrote:
> Assuming that by "bare strings" you mean:
>
> $foo[bar] = 'baz';
>
> as opposed to:
>
> $foo['bar'] = 'baz';

Yes, indeed.

> That is generally considered very bad form in PHP.  That throws an E_NOTICE
> error level, and therefore slows down your code (if only by a small amount)
> for the error handling.  Of course, if you have any respect for your code
> you're developing under E_ALL so bare strings for array keys would print
> ugly notices messages at you constantly.  If you're not developing under
> E_ALL, then you're going to miss error messages that will take a long time
> to track down and correct yourself when the PHP interpreter can simply tell
> you exactly where they are if you let it.

My first little app which is about an hour old is a command line
utility for personal use and to be honest, I haven't checked the logs
or the settings of php.ini so I don't know what the warning level is
set at. I did not know that the interpreter emitted such a warning for
bare strings. So it's settled for me: check my php.ini to ensure that
I run at E_ALL | E_STRICT | E_NOTICE and refrain from using bare
strings.

Thanks for your thoughts and the reminder.

Regards.


> Bottom line: Bare strings are not officially deprecated, but no respectable
> programmer users them.
>
> (I now expect to get flamed by someone who uses them but is insulted that I
> am calling them not respectable.  My position on the matter still stands.)
>
> --Larry Garfield
>
> On 1/14/11 9:44 AM, Evil Son wrote:
>>
>> Hello group,
>>
>> I am a new and just an occasional user of PHP and would like some
>> direction.
>>
>> I find the use of bare strings as array keys pleasant to work with,
>> easy on the eye and quick to type. I understand that this use of bare
>> strings is not encouraged because of possible conflicts with key words
>> and constants and to a lesser degree loss of some performance.
>>
>> I tend to use all capitals for my constants and never for my array
>> keys (if bare). In addition, collisions with PHP keywords fails fast
>> when they happen. My application is for personal use, and any
>> performance degradation is insignificant.
>>
>> However, I can imagine having collisions with constants defined by
>> libraries that I may use.
>>
>> Have you found the use of bare strings a significant issue? Or do the
>> benefits outweigh the dangers? Perl and Tcl both have them. I like
>> them in PHP too.
>>
>> Thanks.
>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
Regards
Evil Son

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to