Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43865 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17858 invoked from network); 7 May 2009 00:37:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 May 2009 00:37:48 -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.157 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.157 fg-out-1718.google.com Received: from [72.14.220.157] ([72.14.220.157:56034] helo=fg-out-1718.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F2/62-19278-A5D220A4 for ; Wed, 06 May 2009 20:37:47 -0400 Received: by fg-out-1718.google.com with SMTP id 22so1056706fge.0 for ; Wed, 06 May 2009 17:37:44 -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=OudsSmf2stRaF9TEkC7tyFU76gamtvd5SdZ0rU4tKUM=; b=OKOs0NkKe4DlgDpIki08dcZwWikWuZ1aYSIdNan5tXL3qfb9NxuFcb8c+Qg7UTIqUx pnNVY+I2DxINgMxx6vegd/T34Loeq7hDzwS/sbNoLpdUlSUv1a7k6+ugwGWBOdcuqWN0 T5+mFCo7CWGiqhIwapBR5SdRWTBsAqg93A67c= 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=QR8MUfAlhnUyo7XxCrgrwSP6aMfOeGqauMM69LKVfIzGSn0oOOj7+jcaG9OmSCkH2o I+Hl4JM+3IpTWDF8D8BYT4Zx9ljMr5qyqF8Blam8tzJMi1ltemPfXO9eYBcjnzDZOeSZ BlkaE0dg5yMDyx+wCErPag0Q8HtTllup8FVsM= MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.86.33.10 with SMTP id g10mr1930738fgg.21.1241656663970; Wed, 06 May 2009 17:37:43 -0700 (PDT) In-Reply-To: References: <4A01A9C3.5010108@smashlabs.com> Date: Thu, 7 May 2009 02:37:43 +0200 X-Google-Sender-Auth: 0c136a5255174a0a Message-ID: To: Ralph Schindler Cc: internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RecursiveFilterItrator possible issues with inheritance From: webmaster@colder.ch (Etienne Kneuss) Hello, On Wed, May 6, 2009 at 5:35 PM, Etienne Kneuss wrote: > Hello, > > On Wed, May 6, 2009 at 5:16 PM, Ralph Schindler wro= te: >> 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 additi= onal >> __construct() arguments (for configuring its behavior). =A0The reason it= s >> 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 =3D array('a' =3D> array('ab', 'ac', 'ad' =3D> array('ada', 'adc= ')), 'b' >> =3D> array('bb', 'bc')); >> >> $ri =3D new RecursiveArrayIterator($rArray); >> $filter =3D new MyRFI($ri, 'argument'); >> $iterator =3D new RecursiveIteratorIterator($filter); >> >> foreach ($iterator as $key =3D> $item) { >> =A0 =A0echo $key . ' - ' . $item . PHP_EOL; >> } >> >> class MyRFI extends RecursiveFilterIterator >> { >> =A0 =A0protected $_otherArg =3D null; >> >> =A0 =A0public function __construct($iterator, $otherArg =3D null) >> =A0 =A0{ >> =A0 =A0 =A0 =A0$r =3D new ReflectionClass($this); >> =A0 =A0 =A0 =A0$this->_otherArg =3D $otherArg; >> =A0 =A0 =A0 =A0parent::__construct($iterator); >> =A0 =A0} >> >> =A0 =A0public function accept() >> =A0 =A0{ >> =A0 =A0 =A0 =A0echo ($this->_otherArg) ? 'Arg Present' : 'Arg NOT Presen= t'; >> =A0 =A0 =A0 =A0echo PHP_EOL; >> =A0 =A0 =A0 =A0return true; >> =A0 =A0} >> >> >> 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() insi= de >> 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. =A0And since the >> implementation is in the extension, the typical developer would generall= y >> not understand how getChildren() really works under the hood. Sorry for the false hope, it is indeed how it's supposed to work and not a bug. Since the new iterator is instanciated directly inside getChildren, you can't magically have new arguments to your constructor and have them filled appropriately. But you can basically implement all features you want by simply overriding getChildren. Clone + setiterator could also work, but changing that would introduce BC breaks, and I'm not sure it would make more sense than what we have now. Regards >> >> 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 > --=20 Etienne Kneuss http://www.colder.ch Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal