Re: Bare Strings, are they deprecated?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Assuming that by "bare strings" you mean:

$foo[bar] = 'baz';

as opposed to:

$foo['bar'] = 'baz';

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.

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux