Re: php seems to be inconsistent in its handling of backslashes ... maybe?
| From: | Richard Lynch | Date: | Wed, 25 Apr 2007 02:44:53 +0000 |
| Subject: | Re: php seems to be inconsistent in its handling of backslashes ... maybe? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-253656@lists.php.net to get a copy of this message | ||
On Mon, April 23, 2007 8:36 am, Philip Thompson wrote:
> On Apr 22, 2007, at 1:29 AM, Richard Lynch wrote:
>
>> On Sun, April 22, 2007 12:54 am, ufan100@gmail.com wrote:
>>> -- or maybe it's just the PCRE extension
>>> -- or quite likely I have got something wrong
>>>
>>> Hello members,
>>> I'm hoping you could enlighten me.
>>>
>>> Using error_reporting = E_ALL | E_STRICT, I tested the
>>> following statements:
>>
>> PHP interprets \\ inside of '' to turn \\ into \
>>
>> It also tries to be halfway smart about mistakes with \ followed by
>> some other non-special character, by just pretending you knew what
>> you
>> were doing and had \\ there to get just one \, even though you
>> didn't.
>
> Not that I can deny Richard's infinite knowledge of PHP (and it
> *eating* code), but is it PHP's responsibility to determine what the
> user has typed is (in)correct AND try to *fix* it? Shouldn't PHP just
> assume the programmer is not a complete idiot? If there's an error/
> warning/etc, throw it but don't correct it.
The actual documented feature is that \ followed by anything other
than the characters defined to be special (another \, n, t, r various
hex and octal codes) just turns into a plain old \
To *ME* that means you *SHOULD* have had \\ there, since \ is the
escape character you use to get a \ inside of a string.
I've seen too many people go from:
"This is \best"
to
"This ia a \test"
and they do NOT understand why the heck \b and \t didn't work the same...
I'd be ecstatic if PHP gave a syntax error for a stray \ inside a
string, personally, but apparently I'm in the minority.
\\ is one of my regular rants, so you'll be hearing this again :-)
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?