Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53781 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55285 invoked from network); 8 Jul 2011 13:27:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jul 2011 13:27:17 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@googlemail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.215.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@googlemail.com X-Host-Fingerprint: 209.85.215.170 mail-ey0-f170.google.com Received: from [209.85.215.170] ([209.85.215.170:45278] helo=mail-ey0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/F0-48961-3B5071E4 for ; Fri, 08 Jul 2011 09:27:16 -0400 Received: by eyf5 with SMTP id 5so643386eyf.29 for ; Fri, 08 Jul 2011 06:27:13 -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=jB2PuC/dx2N8TqecLAO2Pj7vcchoGEo4POOj9QrawKo=; b=Od6mLnF1gVL3deWLlTbU7Bq9POrkE6So1yXQ2YxHbVWVXmPV3Tc2Eg7WRZjKe355xb 9gcArGJiu/U46PxWyTqfvFuOpp1O5srYQ8CtDEr/rg1TXJ7CNEwTK3+19STH9KK1fGCA 17wanyvabCo/MBO3uyQ521OwovGm36Rk+Fbso= MIME-Version: 1.0 Received: by 10.14.187.143 with SMTP id y15mr587140eem.182.1310131632914; Fri, 08 Jul 2011 06:27:12 -0700 (PDT) Received: by 10.14.99.131 with HTTP; Fri, 8 Jul 2011 06:27:12 -0700 (PDT) In-Reply-To: References: Date: Fri, 8 Jul 2011 15:27:12 +0200 Message-ID: To: Rafael Dohms Cc: PHP internals Content-Type: multipart/alternative; boundary=bcaec52be68196c0ef04a78ecabe Subject: Re: [PHP-DEV] preg_match From: nikita.ppv@googlemail.com (Nikita Popov) --bcaec52be68196c0ef04a78ecabe Content-Type: text/plain; charset=ISO-8859-1 No, you don't need to initialize $matches. It's passed by reference and thus doesn't need to be initialized. And as I already said: It is good practice to ensure that preg_match actually matched something: if (preg_match(REGEX, $string, $matches)) { // in here $matches is guaranteed to be defined } If you don't do that you will work with $matches even though there was no match - which is pointless and will probably result in bugs. On Fri, Jul 8, 2011 at 3:18 PM, Rafael Dohms wrote: > 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 > --bcaec52be68196c0ef04a78ecabe--