Re: preg_match too greedy
| From: | Ben Dunlap | Date: | Thu, 30 Jul 2009 16:33:49 +0000 |
| Subject: | Re: preg_match too greedy | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296067@lists.php.net to get a copy of this message | ||
>>>> echo (preg_match($pattern, $test) != false)
>>
>> The " != false " here is redundant.
>
> Understood. But what you think is redundancy is, to me, clarity in
> programming. I happen to think that boolean tests shouldn't ride on
> whether or not an array returned from a function is empty or not (or a
> freaking boolean). If what I'm looking for is a "false" then that's what
> I'll test for.
Fair enough, but in that case I think you want "!== false". The expression you
have -- "($x != false)" -- will be true whether $x is 0, NULL, an empty string,
an empty array, or actually FALSE.
But "$x !== false" will only be true in the last case.
Ben