RE: [PHP-DEV] regex operators
| From: | Rasmus Lerdorf | Date: | Tue, 14 Oct 2003 17:10:14 +0000 |
| Subject: | RE: [PHP-DEV] regex operators | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-4837@lists.php.net to get a copy of this message | ||
On Tue, 14 Oct 2003, David Sklar wrote:
> On Tuesday, October 14, 2003 11:18 AM, mailto:derick@php.net
> wrote:
>
> > Right, and as George's example already works I see no point in adding
> > more 'magic' operators that look like Perl to me.
>
> What about a match operator? I realize that similar functionality can be
> achieved with preg_match(), but we could duplicate all operators with
> functions: if (equals($foo,$bar)) {} instead of if ($foo == bar). Obviously,
> testing equality is a frequent enough operation that it would be clumsy to
> not have an == operator. In the same vein, matching against a regex seems
> like a more frequent operation in web programming than, say bitshifting with
> assignment ala the <<= and >>= operators. Which is why I think it could be a
> useful addition.
You are pushing towards
$_~=/^\.*?\$$/;
This is not human-readable code and one of the basic characteristics that
sets PHP apart from Perl. Every non-trivial line of PHP code has a
decypherable keyword that you can plug into the manual to figure out what
that line is doing. We make sure of this by keeping the number of
operators to a minimum. As for your bitshifting example. It has nothing
to do with the frequency of use, it has to do with readability.
-Rasmus