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

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

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.