note 111353 deleted from class.callbackfilteriterator by danbrown

From: Date: Tue, 05 Mar 2013 16:07:50 +0000
Subject: note 111353 deleted from class.callbackfilteriterator by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193915@lists.php.net to get a copy of this message
Note Submitter: da dot vinci7 at spamaway dot gmail dot com ---- @dave1010, you posted an example for the CallbackFilterClass, it a good example, but if you googled you would also have found this link http://www.php.net/~helly/php/ext/spl/callbackfilteriterator_8inc_source.html which is a the PHP version of what has been implemented in php 5.4 BTW here is my extended version of the above link with the abillity to switch the filter on the fly using the reflector class <?php final class ExtendedCallbackFilterIterator extends \CallbackFilterIterator { /** * Set or change the callback function * @param callback $callback The (new) function to use as callback * @throws \InvalidArgumentException when $callback isn't valid */ public function setCallback( $callback ) { if ( !is_callable( $callback ) ) { throw new \InvalidArgumentException( 'Argument 1 passed to '.__CLASS__.'::'.__METHOD__.' must be a valid callback.' ); } $rf = new \ReflectionProperty( 'CallbackFilterIterator', 'callback' ); $rf->setAccessible(true); $rf->setValue($this, $callback); } } ?>

« previous php.notes (#193915) next »