Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53778 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45702 invoked from network); 8 Jul 2011 12:21:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jul 2011 12:21:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@googlemail.com X-Host-Fingerprint: 209.85.215.42 mail-ew0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:38564] helo=mail-ew0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 50/00-45592-936F61E4 for ; Fri, 08 Jul 2011 08:21:14 -0400 Received: by ewy2 with SMTP id 2so632718ewy.29 for ; Fri, 08 Jul 2011 05:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=b0vM/5Ur7n7uWAUzEnralTvhc5T4vzwbcJQkurZy6gE=; b=JtMxtEhRscgEKp7FCwBGcwDUvhWv4IM+1HDVGkRZb9HDjISoyjiEdh+Y41uRpZp9rT 5VtxQ3fCeRyy9ESe81OLm9+quSttJelh0xSGq2Yy1iec4FdPCsMlbQRUcu/B2Kg13hPJ aG6z10+4fjXReEfFM7qzvZtJd0Y8JaIs0QG68= MIME-Version: 1.0 Received: by 10.14.47.13 with SMTP id s13mr592754eeb.214.1310127626222; Fri, 08 Jul 2011 05:20:26 -0700 (PDT) Received: by 10.14.99.131 with HTTP; Fri, 8 Jul 2011 05:20:26 -0700 (PDT) In-Reply-To: References: Date: Fri, 8 Jul 2011 14:20:26 +0200 Message-ID: To: Rafael Dohms Cc: PHP internals Content-Type: multipart/alternative; boundary=90e6ba5bb905c57ba304a78ddb51 Subject: Re: [PHP-DEV] preg_match From: nikita.ppv@googlemail.com (Nikita Popov) --90e6ba5bb905c57ba304a78ddb51 Content-Type: text/plain; charset=ISO-8859-1 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. On Fri, Jul 8, 2011 at 2:12 PM, Rafael Dohms wrote: > I was wondering if anyone ever thought of either fixing or writing a > new function that would make preg_match actually work in a way that > made sense? > > right now i need to pass in a optional parameter that will receive the > match, in this case one or no match, why should this not be the > function's return already? > > something like: > > $string = "my text"; > $result = preg_match("/\(.*)\<\/td\>/", $string); > > $result // = "my text" > > Maybe something like preg_extract? I do not have the C skills to write > a patch but i think adding a new function would not break BC or have > negative side effects, would it? > > -- > Rafael Dohms > PHP Evangelist and Community Leader > http://www.rafaeldohms.com.br > http://www.phpsp.org.br > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --90e6ba5bb905c57ba304a78ddb51--