Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43863 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20274 invoked from network); 6 May 2009 15:41:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 May 2009 15:41:08 -0000 Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 72.14.220.159 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 72.14.220.159 fg-out-1718.google.com Received: from [72.14.220.159] ([72.14.220.159:54695] helo=fg-out-1718.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/00-19278-39FA10A4 for ; Wed, 06 May 2009 11:41:07 -0400 Received: by fg-out-1718.google.com with SMTP id 22so970973fge.0 for ; Wed, 06 May 2009 08:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=Nofmpvy3bcMyNPK1JwvfTLVf6d/jfEd3eLOtGnKjGNg=; b=MVzcNmFKY1dQvILZyYPnXZxGfAODg2mg+L4pfclLB+1mIkCyOo7STV+ane/3rR5wbc Ym6n5hWDDgDlgIaLM/XseE9xnxZTnhlt9z3ZkP/ly9aMkUGB/pRhct38x1e6deYku5+2 j1PO3FL4lKrL/BdCboIhpDyKxShLcAFGSa08g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=xMgHDgUpEX7v/5fTrvVp+mjMhyHghiePEzaCjzXktelUl8dgEyexGRZtIIwgjcqCNp Uu30wssTd5VUB+vhpPH9lF6xAyOk810rBwTeev1JlQyoGMsK0BNizY4PmFf755F/GZL4 YwLyj6slRSx07wXxld6ktDeNv6YwZ8IU+iQM4= MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.86.4.7 with SMTP id 7mr1418299fgd.46.1241624146236; Wed, 06 May 2009 08:35:46 -0700 (PDT) In-Reply-To: <4A01A9C3.5010108@smashlabs.com> References: <4A01A9C3.5010108@smashlabs.com> Date: Wed, 6 May 2009 17:35:46 +0200 X-Google-Sender-Auth: 3890f25c277f1661 Message-ID: To: Ralph Schindler Cc: internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RecursiveFilterItrator possible issues with inheritance From: webmaster@colder.ch (Etienne Kneuss) Hello, On Wed, May 6, 2009 at 5:16 PM, Ralph Schindler wrote: > Hi all, > > I'd like to confirm something as a bug and/or design issue. This is a bug, could you please report it and assign it to me ? Thanks, > > Currently, its difficult to extend RecursiveFilterIterator() with additional > __construct() arguments (for configuring its behavior). The reason its > difficult is b/c when getChildren() is called, a new instance of the RFI is > created (only way you'd know this is if you look into the source of RFI). > > Ideally, this code would work: > > > $rArray = array('a' => array('ab', 'ac', 'ad' => array('ada', 'adc')), 'b' > => array('bb', 'bc')); > > $ri = new RecursiveArrayIterator($rArray); > $filter = new MyRFI($ri, 'argument'); > $iterator = new RecursiveIteratorIterator($filter); > > foreach ($iterator as $key => $item) { > echo $key . ' - ' . $item . PHP_EOL; > } > > class MyRFI extends RecursiveFilterIterator > { > protected $_otherArg = null; > > public function __construct($iterator, $otherArg = null) > { > $r = new ReflectionClass($this); > $this->_otherArg = $otherArg; > parent::__construct($iterator); > } > > public function accept() > { > echo ($this->_otherArg) ? 'Arg Present' : 'Arg NOT Present'; > echo PHP_EOL; > return true; > } > > > The current output would be: > > > ~/tmp/test-rii-filter$ php test-rii-problem.php > Arg Present > Arg NOT Present > 0 - ab > Arg NOT Present > 1 - ac > Arg NOT Present > Arg NOT Present > 0 - ada > Arg NOT Present > 1 - adc > Arg Present > Arg NOT Present > 0 - bb > Arg NOT Present > 1 - bc > > > The ideal output would be: > > Arg Present > Arg Present > 0 - ab > Arg Present > 1 - ac > Arg Present > Arg Present > 0 - ada > Arg Present > 1 - adc > Arg Present > Arg Present > 0 - bb > Arg Present > 1 - bc > > > > > The only proposed change I could would be to make the getChildren() inside > of RecursiveFilterIterator use clone & add a method called setIterator() > instead of Reflection::newInstance($iterator) > > Is this possible? Or is extending and overriding getChildren() the best > strategy here? > > Reason I post is b/c it seems like using clone/setIterator() would > facilitate better inheritance / better polymorphism. And since the > implementation is in the extension, the typical developer would generally > not understand how getChildren() really works under the hood. > > Thanks, > Ralph > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Etienne Kneuss http://www.colder.ch Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal