Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53780 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53503 invoked from network); 8 Jul 2011 13:18:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jul 2011 13:18:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=listas@rafaeldohms.com.br; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=listas@rafaeldohms.com.br; sender-id=unknown Received-SPF: error (pb1.pair.com: domain rafaeldohms.com.br from 209.85.220.170 cause and error) X-PHP-List-Original-Sender: listas@rafaeldohms.com.br X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:40966] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E4/A0-48961-DA3071E4 for ; Fri, 08 Jul 2011 09:18:38 -0400 Received: by vxi39 with SMTP id 39so1547653vxi.29 for ; Fri, 08 Jul 2011 06:18:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.22.39 with SMTP id a7mr2495933vdf.73.1310131114952; Fri, 08 Jul 2011 06:18:34 -0700 (PDT) Received: by 10.52.113.165 with HTTP; Fri, 8 Jul 2011 06:18:34 -0700 (PDT) In-Reply-To: References: Date: Fri, 8 Jul 2011 10:18:34 -0300 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] preg_match From: listas@rafaeldohms.com.br (Rafael Dohms) On Fri, Jul 8, 2011 at 9:20 AM, Nikita Popov wrote: > The most common use for preg_match is validation: > > if (!preg_match('~...~', $string)) { /* do something */ } > > Here $matches is not required, only the 0/1 return value of preg_match is of > interest. > > Furthermore, even if you need $matches, you should always combine it with an > if: > > if (!preg_match('~...~', $string, $matches)) { /* do something with $matches > */ } > > Otherwise you will access $matches even though the match failed (which will > result in errors). > > Thus: There is no need to change behavior here. That is just one use case as i see it its very cluncky to use this in case you want to extract matches, you need to initilize the $matches variable beforehad or you get a notice, so a simple extract is now 3 lines of code. Thus, that is the reason why i suggest a new preg_extract function that would handle the other use cases in a optimized way. -- Rafael Dohms PHP Evangelist and Community Leader http://www.rafaeldohms.com.br http://www.phpsp.org.br