Re: Bare Strings, are they deprecated?

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

 



On 14 January 2011 16:06, Evil Son <ewilsonmail@xxxxxxxxx> wrote:
> On Sat, Jan 15, 2011 at 1:51 AM, larry@xxxxxxxxxxxxxxxx
> <larry@xxxxxxxxxxxxxxxx> 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
>
>

error_reporting=-1
display_errors=On

will turn on everything and tell you about it.

Alternatively, take a look at the setting of php.ini-development. This
is the recommended settings for developing with PHP, as opposed to
php.ini-production which is the recommend settings for running PHP in
a live environment.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
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