Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64382 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26638 invoked from network); 20 Dec 2012 16:31:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Dec 2012 16:31:43 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.28 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.28 out4-smtp.messagingengine.com Received: from [66.111.4.28] ([66.111.4.28:50087] helo=out4-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4D/77-20281-E6D33D05 for ; Thu, 20 Dec 2012 11:31:42 -0500 Received: from compute1.internal (compute1.nyi.mail.srv.osa [10.202.2.41]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id B543520492 for ; Thu, 20 Dec 2012 11:31:39 -0500 (EST) Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute1.internal (MEProxy); Thu, 20 Dec 2012 11:31:39 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=pesguaD12adOAQ9tFLBkYy yxOcA=; b=O3SlSntHg2FrGBE536OnuWIHD7rP80GZHpfibV807wnoLVkQlfDOB4 FnXXiPrGzBKxOA0S/CNF3gkK60HP14AkgH26/nlP4RqIN+h5noC0xxzwxP2wP0Rq h/XvbbM7FI7Sw2Yk+7MzydeSigwNfCrYnSN4Dp7k3t+D6XIc0OHRo= X-Sasl-enc: yTxk+qIwPUcCLGiwxJAQIdu2Ic1XOzEE4bMm8SRjM2Nu 1356021099 Received: from Palantirs-MacBook-Pro.local (unknown [209.41.114.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 6CE66482593 for ; Thu, 20 Dec 2012 11:31:39 -0500 (EST) Message-ID: <50D33D6B.4060404@garfieldtech.com> Date: Thu, 20 Dec 2012 10:31:39 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: internals@lists.php.net References: <50D05CD0.8080206@php.net> <50D06E8B.9020807@php.net> <50D24B4C.4070901@garfieldtech.com> <50D29483.20802@oracle.com> In-Reply-To: <50D29483.20802@oracle.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays From: larry@garfieldtech.com (Larry Garfield) On 12/19/12 10:30 PM, Christopher Jones wrote: > > > On 12/19/2012 03:18 PM, Larry Garfield wrote: >> You could likely simplify the code even further using an infinite >> iterator: >> >> http://us1.php.net/infiniteiterator >> >> $result = preg_replace_callback( >> '/word/', >> function($matches) use (&$replacements_iterator) { >> return $replacements->next(); >> }, >> 'word word word word word' >> ); >> >> --Larry Garfield >> > > What am I missing that causes the first call to > $replacements_iterator->current() to return NULL > unless the iterator is rewound before use? Eh, nothing. You're right, next() doesn't return an element, it just advances, so you still need the current() call. Which seems kinda silly to me, but whatev. --Larry Garfield