SlideShare a Scribd company logo
1 of 20

      
       An Introduction to  SPL ,  
       the  S tandard  P HP  L ibrary 
      
     
      
       
      
     
      
       Robin Fernandes (  [email_address]  / @rewbs )

      
       What is SPL? 
       
       A collection of  classes and interfaces  for   solving  common programming problems . 
       
       ,[object Object],

      
       Why use SPL? 
       ,[object Object],
       
      
     
      
       
       
       
       
       Zend 
       Framework 
      
     
      
       
      
     
      
       
       
       
       
       
       Agavi

      
       SPL Documentation 
       ,[object Object],

      
       SPL Data Structures 
       ,[object Object],

      
       Iterators 
       ,[object Object],
       An  iterator  implements a  consistent interface  for  traversing a collection . 
       ,[object Object],
       
       ,[object Object],
       Iterators  decouple collections from algorithms  by encapsulating traversal logic.

      
       Without Iterators 
      
     
      
       ... 
      
     
      
       ... 
      
     
      
       Algorithms: 
      
     
      
       ... 
      
     
      
       ... 
      
     
      
       ... 
      
     
      
       ... 
      
     
      
       ... 
      
     
      
       ... 
      
     
      
       Sum: 
      
     
      
       Average: 
      
     
      
       Display: 
      
     
      
       Collections: 
      
     
      
       
      
      
       1 
      
      
       2 
      
      
       3 
      
      
       4 
      
     
      
       1 
      
      
       4 
      
      
       5 
      
      
       3 
      
      
       2

      
       With Iterators 
      
     
      
       ... 
      
     
      
       Collections: 
      
     
      
       Algorithms: 
      
     
      
       ... 
      
     
      
       Iterators: 
      
     
      
       Algorithms are 
       decoupled 
       from collections! 
      
     
      
       
      
      
       1 
      
      
       2 
      
      
       3 
      
      
       4 
      
     
      
       1 
      
      
       4 
      
      
       5 
      
      
       3 
      
      
       2

      
       Iterators in PHP 
       ,[object Object],
       
       
       ,[object Object],
      
     
      
       interface  Iterator  extends  Traversable { 
       function  rewind(); 
       function  valid(); 
       function  current(); 
       function  key(); 
       function  next(); 
       } 
      
     
      
       interface  IteratorAggregate  extends  Traversable { 
       function  getIterator(); 
       }

      
       Iterators in PHP 
       
      
     
      
       class  MyList 
       implements  IteratorAggregate { 
       
       private  $nodes  = ...; 
       
       
       function  getIterator() { 
       return new  MyListIterator( $this ); 
       } 
       
       } 
      
     
      
       class  MyGraph 
       implements  IteratorAggregate { 
       
       private  $nodes  = ...; 
       private  $edges  = ...; 
       
       function  getIterator() { 
       return new  MyGraphIterator( $this ); 
       } 
       
       } 
      
     
      
       function  show( $collection ) { 
       
       foreach  ( $collection  as  $node ) { 
       echo  &quot; $node <br/>&quot; ; 
       } 
       
       } 
      
     
      
       echo  show( new  MyList); 
      
     
      
       echo  show( new  MyGraph);

      
       Iterators in PHP 
       Traversable objects get  special foreach treatment : 
      
     
      
       foreach  ( $traversableObj  as  $key  =>  $value ) { 
       // Loop body 
       } 
      
     
      
       // 1. Get the Iterator instance from $traversableObj: 
       if  ( $traversableObj  instanceof  Iterator) { 
       $iterator  =  $traversableObj ; 
       }  else if  ( $traversableObj  instanceof  IteratorAggregate){ 
       $iterator  =  $traversableObj ->getIterator(); 
       } 
       
       // 2. Loop using the methods provided by Iterator: 
       $iterator ->rewind(); 
       while  ( $iterator ->valid()) { 
       $value  =  $iterator ->current(); 
       $key  =  $iterator ->key(); 
       // Loop body 
       $iterator ->next(); 
       } 
      
     
      
       <=> 
      
     
      
       …   is equivalent to   ... 
      
     
      
       Note: 
       
       ,[object Object],
       
       - No class can implement both Iterator  and  IteratorAggregate.

      
       SPL Iterators 
       
      
     
      
       Iterator decorators: 
       AppendIterator 
       CachingIterator 
       FilterIterator 
       InfiniteIterator 
       IteratorIterator 
       LimitIterator 
       MultipleIterator  (5.3) 
       NoRewindIterator 
       ParentIterator 
       RegexIterator 
       RecursiveIteratorIterator 
       RecursiveCachingIterator 
       RecursiveFilterIterator 
       RecursiveRegexIterator 
       RecursiveTreeIterator  (5.3) 
      
     
      
       Concrete iterators: 
       ArrayIterator 
       RecursiveArrayIterator 
       DirectoryIterator 
       RecursiveDirectoryIterator 
       EmptyIterator 
       FilesystemIterator  (5.3) 
       GlobIterator  (5.3) 
      
     
      
       Unifying interfaces: 
       RecursiveIterator 
       SeekableIterator 
       OuterIterator

      
       More Iterators... 
       ,[object Object],
      
     
      
       $s  =  new  SplStack(); 
       $i  =  new  InfiniteIterator ( $s ); 
       $s ->push( 1 );  $s ->push( 2 );  $s ->push( 3 ); 
       foreach  ( $i  as  $v ) { 
       echo  &quot; $v  &quot; ;  //3 2 1 3 2 1 3 2 1 3 2... 
       }

      
       A Note on Recursive Iterators... 
       ,[object Object],
      
     
      
       $a  =  array ( 1 ,  2 ,  array ( 3 ,  4 )); 
       $i  =  new  RecursiveArrayIterator( $a ); 
       foreach  ( $i  as  $v ) {  echo  &quot; $v  &quot; ; }  // 1 2 Array 
      
     
      
       $a  =  array ( 1 ,  2 ,  array ( 3 ,  4 )); 
       $i  =  new  RecursiveArrayIterator( $a ); 
       $i  =  new  RecursiveIteratorIterator ( $i ); 
       foreach  ( $i  as  $v ) {  echo  &quot; $v  &quot; ; }  // 1 2 3 4

      
       SPL Iterators 
       
      
     
      
       Iterator decorators: 
       AppendIterator 
       CachingIterator 
       FilterIterator 
       InfiniteIterator 
       IteratorIterator 
       LimitIterator 
       MultipleIterator  (5.3) 
       NoRewindIterator 
       ParentIterator 
       RegexIterator 
       RecursiveIteratorIterator 
       RecursiveCachingIterator 
       RecursiveFilterIterator 
       RecursiveRegexIterator 
       RecursiveTreeIterator  (5.3) 
      
     
      
       Concrete iterators: 
       ArrayIterator 
       RecursiveArrayIterator 
       DirectoryIterator 
       RecursiveDirectoryIterator 
       EmptyIterator 
       FilesystemIterator  (5.3) 
       GlobIterator  (5.3) 
      
     
      
       Unifying interfaces: 
       RecursiveIterator 
       SeekableIterator 
       OuterIterator

      
       SPL Exceptions 
      
     
      
       
      
     
      
       ,[object Object],
       
       ,[object Object],
       
       ,[object Object],
       ,[object Object],
       Benefits: 
       -> Improve  consistency of exception use  within & across projects. 
       
       -> Increase the  self-documenting  nature of your code.

      
       More SPL Stuff... 
       ,[object Object],

      
       Testing SPL 
       ,[object Object],

      
       Come to TestFest! 
       ,[object Object],
       
       ,[object Object],

      
       Iterators – bonus 
       What's this Traversable interface all about? 
       ,[object Object],

More Related Content

What's hot

Smalltalk implementation of EXIL, a Component-based Programming Language
 Smalltalk implementation of EXIL, a Component-based Programming Language Smalltalk implementation of EXIL, a Component-based Programming Language
Smalltalk implementation of EXIL, a Component-based Programming LanguageESUG
 
Java Programming Guide Quick Reference
Java Programming Guide Quick ReferenceJava Programming Guide Quick Reference
Java Programming Guide Quick ReferenceFrescatiStory
 
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...DrupalMumbai
 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Javahendersk
 
PyCon UK 2008: Challenges for Dynamic Languages
PyCon UK 2008: Challenges for Dynamic LanguagesPyCon UK 2008: Challenges for Dynamic Languages
PyCon UK 2008: Challenges for Dynamic LanguagesTed Leung
 
Java Reference
Java ReferenceJava Reference
Java Referencekhoj4u
 
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]Tom Lee
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHackito Ergo Sum
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5Sowri Rajan
 
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...lennartkats
 
Strategies to improve embedded Linux application performance beyond ordinary ...
Strategies to improve embedded Linux application performance beyond ordinary ...Strategies to improve embedded Linux application performance beyond ordinary ...
Strategies to improve embedded Linux application performance beyond ordinary ...André Oriani
 
Know yourengines velocity2011
Know yourengines velocity2011Know yourengines velocity2011
Know yourengines velocity2011Demis Bellot
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5Sowri Rajan
 
Using Stratego/XT for generation of software connectors.
Using Stratego/XT for generation of software connectors.Using Stratego/XT for generation of software connectors.
Using Stratego/XT for generation of software connectors.Michal Malohlava
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)goccy
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's RevengeErin Dees
 
Analysis Software Development
Analysis Software DevelopmentAnalysis Software Development
Analysis Software DevelopmentAkira Shibata
 

What's hot (20)

Smalltalk implementation of EXIL, a Component-based Programming Language
 Smalltalk implementation of EXIL, a Component-based Programming Language Smalltalk implementation of EXIL, a Component-based Programming Language
Smalltalk implementation of EXIL, a Component-based Programming Language
 
Java Programming Guide Quick Reference
Java Programming Guide Quick ReferenceJava Programming Guide Quick Reference
Java Programming Guide Quick Reference
 
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Java
 
PyCon UK 2008: Challenges for Dynamic Languages
PyCon UK 2008: Challenges for Dynamic LanguagesPyCon UK 2008: Challenges for Dynamic Languages
PyCon UK 2008: Challenges for Dynamic Languages
 
Java Reference
Java ReferenceJava Reference
Java Reference
 
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 
Intel open mp
Intel open mpIntel open mp
Intel open mp
 
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
 
Strategies to improve embedded Linux application performance beyond ordinary ...
Strategies to improve embedded Linux application performance beyond ordinary ...Strategies to improve embedded Linux application performance beyond ordinary ...
Strategies to improve embedded Linux application performance beyond ordinary ...
 
Know yourengines velocity2011
Know yourengines velocity2011Know yourengines velocity2011
Know yourengines velocity2011
 
Project Coin
Project CoinProject Coin
Project Coin
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 
Using Stratego/XT for generation of software connectors.
Using Stratego/XT for generation of software connectors.Using Stratego/XT for generation of software connectors.
Using Stratego/XT for generation of software connectors.
 
C tutorial
C tutorialC tutorial
C tutorial
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's Revenge
 
Analysis Software Development
Analysis Software DevelopmentAnalysis Software Development
Analysis Software Development
 

Similar to An Introduction to SPL, the Standard PHP Library

Using spl tools in your code
Using spl tools in your codeUsing spl tools in your code
Using spl tools in your codeElizabeth Smith
 
Spl in the wild - zendcon2012
Spl in the wild - zendcon2012Spl in the wild - zendcon2012
Spl in the wild - zendcon2012Elizabeth Smith
 
SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09Elizabeth Smith
 
Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Elizabeth Smith
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;b>PHP&lt;/b> Reference: Beginner to Intermediate &lt;b>PHP5&lt;/b>
&lt;b>PHP&lt;/b> Reference: Beginner to Intermediate &lt;b>PHP5&lt;/b>&lt;b>PHP&lt;/b> Reference: Beginner to Intermediate &lt;b>PHP5&lt;/b>
&lt;b>PHP&lt;/b> Reference: Beginner to Intermediate &lt;b>PHP5&lt;/b>tutorialsruby
 
Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014Renzo Borgatti
 
Whoops! where did my architecture go?
Whoops! where did my architecture go?Whoops! where did my architecture go?
Whoops! where did my architecture go?Oliver Gierke
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 
gumiStudy#3 Django – 次の一歩
gumiStudy#3 Django – 次の一歩gumiStudy#3 Django – 次の一歩
gumiStudy#3 Django – 次の一歩gumilab
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experiencedzynofustechnology
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterJAXLondon2014
 
Lambdas And Streams in JDK8
Lambdas And Streams in JDK8Lambdas And Streams in JDK8
Lambdas And Streams in JDK8Simon Ritter
 

Similar to An Introduction to SPL, the Standard PHP Library (20)

Using spl tools in your code
Using spl tools in your codeUsing spl tools in your code
Using spl tools in your code
 
Spl in the wild - zendcon2012
Spl in the wild - zendcon2012Spl in the wild - zendcon2012
Spl in the wild - zendcon2012
 
Spl in the wild
Spl in the wildSpl in the wild
Spl in the wild
 
Python
PythonPython
Python
 
SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09
 
Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;b>PHP&lt;/b> Reference: Beginner to Intermediate &lt;b>PHP5&lt;/b>
&lt;b>PHP&lt;/b> Reference: Beginner to Intermediate &lt;b>PHP5&lt;/b>&lt;b>PHP&lt;/b> Reference: Beginner to Intermediate &lt;b>PHP5&lt;/b>
&lt;b>PHP&lt;/b> Reference: Beginner to Intermediate &lt;b>PHP5&lt;/b>
 
Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Scilab vs matlab
Scilab vs matlabScilab vs matlab
Scilab vs matlab
 
Whoops! where did my architecture go?
Whoops! where did my architecture go?Whoops! where did my architecture go?
Whoops! where did my architecture go?
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
gumiStudy#3 Django – 次の一歩
gumiStudy#3 Django – 次の一歩gumiStudy#3 Django – 次の一歩
gumiStudy#3 Django – 次の一歩
 
PerlIntro
PerlIntroPerlIntro
PerlIntro
 
PerlIntro
PerlIntroPerlIntro
PerlIntro
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
 
Lambdas And Streams in JDK8
Lambdas And Streams in JDK8Lambdas And Streams in JDK8
Lambdas And Streams in JDK8
 

More from Robin Fernandes

AtlasCamp 2016: Art of PaaS - Lessons learned running a platform for hundreds...
AtlasCamp 2016: Art of PaaS - Lessons learned running a platform for hundreds...AtlasCamp 2016: Art of PaaS - Lessons learned running a platform for hundreds...
AtlasCamp 2016: Art of PaaS - Lessons learned running a platform for hundreds...Robin Fernandes
 
AtlasCamp 2014: Building a Production Ready Connect Add-On
AtlasCamp 2014: Building a Production Ready Connect Add-OnAtlasCamp 2014: Building a Production Ready Connect Add-On
AtlasCamp 2014: Building a Production Ready Connect Add-OnRobin Fernandes
 
Summit2011 satellites-robinf-20110605
Summit2011 satellites-robinf-20110605Summit2011 satellites-robinf-20110605
Summit2011 satellites-robinf-20110605Robin Fernandes
 
Custom Detectors for FindBugs (London Java Community Unconference 2)
Custom Detectors for FindBugs (London Java Community Unconference 2)Custom Detectors for FindBugs (London Java Community Unconference 2)
Custom Detectors for FindBugs (London Java Community Unconference 2)Robin Fernandes
 
Php On Java (London Java Community Unconference)
Php On Java (London Java Community Unconference)Php On Java (London Java Community Unconference)
Php On Java (London Java Community Unconference)Robin Fernandes
 
PHP on Java (BarCamp London 7)
PHP on Java (BarCamp London 7)PHP on Java (BarCamp London 7)
PHP on Java (BarCamp London 7)Robin Fernandes
 

More from Robin Fernandes (6)

AtlasCamp 2016: Art of PaaS - Lessons learned running a platform for hundreds...
AtlasCamp 2016: Art of PaaS - Lessons learned running a platform for hundreds...AtlasCamp 2016: Art of PaaS - Lessons learned running a platform for hundreds...
AtlasCamp 2016: Art of PaaS - Lessons learned running a platform for hundreds...
 
AtlasCamp 2014: Building a Production Ready Connect Add-On
AtlasCamp 2014: Building a Production Ready Connect Add-OnAtlasCamp 2014: Building a Production Ready Connect Add-On
AtlasCamp 2014: Building a Production Ready Connect Add-On
 
Summit2011 satellites-robinf-20110605
Summit2011 satellites-robinf-20110605Summit2011 satellites-robinf-20110605
Summit2011 satellites-robinf-20110605
 
Custom Detectors for FindBugs (London Java Community Unconference 2)
Custom Detectors for FindBugs (London Java Community Unconference 2)Custom Detectors for FindBugs (London Java Community Unconference 2)
Custom Detectors for FindBugs (London Java Community Unconference 2)
 
Php On Java (London Java Community Unconference)
Php On Java (London Java Community Unconference)Php On Java (London Java Community Unconference)
Php On Java (London Java Community Unconference)
 
PHP on Java (BarCamp London 7)
PHP on Java (BarCamp London 7)PHP on Java (BarCamp London 7)
PHP on Java (BarCamp London 7)
 

Recently uploaded

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

An Introduction to SPL, the Standard PHP Library

  • 1. An Introduction to SPL , the S tandard P HP L ibrary Robin Fernandes ( [email_address] / @rewbs )
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Without Iterators ... ... Algorithms: ... ... ... ... ... ... Sum: Average: Display: Collections: 1 2 3 4 1 4 5 3 2
  • 8. With Iterators ... Collections: Algorithms: ... Iterators: Algorithms are decoupled from collections! 1 2 3 4 1 4 5 3 2
  • 9.
  • 10. Iterators in PHP class MyList implements IteratorAggregate { private $nodes = ...; function getIterator() { return new MyListIterator( $this ); } } class MyGraph implements IteratorAggregate { private $nodes = ...; private $edges = ...; function getIterator() { return new MyGraphIterator( $this ); } } function show( $collection ) { foreach ( $collection as $node ) { echo &quot; $node <br/>&quot; ; } } echo show( new MyList); echo show( new MyGraph);
  • 11.
  • 12. SPL Iterators Iterator decorators: AppendIterator CachingIterator FilterIterator InfiniteIterator IteratorIterator LimitIterator MultipleIterator (5.3) NoRewindIterator ParentIterator RegexIterator RecursiveIteratorIterator RecursiveCachingIterator RecursiveFilterIterator RecursiveRegexIterator RecursiveTreeIterator (5.3) Concrete iterators: ArrayIterator RecursiveArrayIterator DirectoryIterator RecursiveDirectoryIterator EmptyIterator FilesystemIterator (5.3) GlobIterator (5.3) Unifying interfaces: RecursiveIterator SeekableIterator OuterIterator
  • 13.
  • 14.
  • 15. SPL Iterators Iterator decorators: AppendIterator CachingIterator FilterIterator InfiniteIterator IteratorIterator LimitIterator MultipleIterator (5.3) NoRewindIterator ParentIterator RegexIterator RecursiveIteratorIterator RecursiveCachingIterator RecursiveFilterIterator RecursiveRegexIterator RecursiveTreeIterator (5.3) Concrete iterators: ArrayIterator RecursiveArrayIterator DirectoryIterator RecursiveDirectoryIterator EmptyIterator FilesystemIterator (5.3) GlobIterator (5.3) Unifying interfaces: RecursiveIterator SeekableIterator OuterIterator
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.