SlideShare a Scribd company logo
SPL, not a bridge too far
Dutch PHP Conference 2009 - Amsterdam
Who am I ?

Michelangelo van Dam
Independent Enterprise PHP consultant


@dragonbe

http://dragonbe.com




              2
Who are you ?


   You know OOP ?
  You know php.net ?
   You know arrays ?




         3
What is SPL ?

               Standard PHP Library
           interfaces, classes and methods
       solve common development problems

As of 5.3 SPL cannot be turned off from the source !



                         4
Why use SPL ?


SPL provides a huge toolkit that assists you to easily
iterate over a diversity of data structures in a
standardized way




                          5
What does it provide ?
•   ArrayObject - approach arrays as objects
•   Iterators - various iterators
•   Interfaces - Countable Interface
•   Exceptions - exceptions to streamline errorhandling
•   SPL Functions - extra functions and autoloader func
•   SplFileInfo - tools for filesystem access
•   Datastructures - structuring data sequences


                            6
ArrayObject


•   provides an interface
    - treat arrays as objects
    - elements are iteratable



                                7
ArrayObject methods
•   ArrayObject::append
•   ArrayObject::__construct
•   ArrayObject::count
•   ArrayObject::getIterator
•   ArrayObject::offsetExists
•   ArrayObject::offsetGet
•   ArrayObject::offsetSet
•   ArrayObject::offsetUnset

                            8
<?php
      ArrayObject w/o SPL
// file: nospl_arrayobject01.php

$myArray =   array (
  quot;monkeyquot;   => quot;bananasquot;,
  quot;rabbitquot;   => quot;carrotsquot;,
  quot;ogrequot;     => quot;onionsquot;,
);


echo quot;Ogres exists ? quot;
  . (key_exists('ogre', $myArray) ? quot;Yesquot; : quot;Noquot;) . quot;nquot;;

echo quot;Ogres equals quot;
  . $myArray['ogre'] . quot;nquot;;




                               9
<?php
      ArrayObject Example
// file: spl_arrayobject01.php

$myArray =   array (
  quot;monkeyquot;   => quot;bananasquot;,
  quot;rabbitquot;   => quot;carrotsquot;,
  quot;ogrequot;     => quot;onionsquot;,
);

// create an object of the array
$arrayObj = new ArrayObject($myArray);

echo quot;Ogres exists ? quot;
  . ($arrayObj->offsetExists(quot;ogrequot;) ? quot;Yesquot; : quot;Noquot;) . quot;nquot;;

echo quot;Ogres equals quot;
  . $arrayObj->offsetGet(quot;ogrequot;) . quot;nquot;;




                                 10
ArrayObject Output
$ /usr/bin/php ./nospl_arrayobject01.php
Ogres exists ? Yes
Ogres equals onions
Execution time: 0.00064299999999995 microseconds.

$ /usr/bin/php ./spl_arrayobject01.php
Ogres exists ? Yes
Ogres equals onions
Execution time: 0.00054399999999999 microseconds.




                               11
Iterator


•   move back and forth in a stack
•   distinct methods to access keys and values




                            12
Iterators
•   ArrayIterator
•   CachingIterator
•   RecursiveCachingIterator
•   DirectoryIterator
•   RecursiveDirectoryIterator
•   FilterIterator
•   LimitIterator
•   ParentIterator
•   RecursiveIteratorIterator

                           13
The ArrayIterator


iteration methods on array objects




                14
ArrayIterator Example Case
•   Array with 3 elements
    - monkey => bananas,
    - rabbit => carrots,
    - ogre => onions
•   display total elements
•   display key/value pairs while looping
•   display key/value pair for 2nd element


                             15
<?php
     ArrayIterator w/o SPL
// file: nospl_iterator01.php
$myArray = array (
    quot;monkeyquot; => quot;bananasquot;,
    quot;rabbitquot; => quot;carrotsquot;,
    quot;ogrequot;   => quot;onionsquot;,
);
echo quot;$myArray has {sizeof($myArray)} elementsnquot;;
foreach ($myArray as $key => $value) {
  echo quot;{$key}: {$value}nquot;;
}
reset($myArray);
next($myArray);
echo quot;elem 2:quot; . key($myArray) . quot;: quot; . current($myArray) . quot;nquot;;




                               16
<?php
       ArrayIterator w/ SPL
// file: spl_iterator01.php
$myArray = array (
  “monkey” => “bananas”,
  “rabbit” => “carrots”,
  “ogre” => “onions”,
);
$arrayObj = new ArrayObject($myArray);
$iterator = $arrayObj->getIterator();
echo quot;$myArray has {$arrayObj->count()} elementsnquot;;
while ($iterator->valid()) {
    echo quot;{$iterator->key()}: {$iterator->current()}nquot;;
    $iterator->next();
}
$iterator->seek(1);
echo quot;elem 2:{$iterator->key()}: {$iterator->current()}nquot;;




                               17
ArrayIterator Output
$ /usr/bin/php ./nospl_iterator01.php
$myArray has 3 elements
monkey: bananas
rabbit: carrots
ogre: onions
elem 2:rabbit: carrots
Execution time: 0.0020509999999999 microseconds.


$ /usr/bin/php ./spl_iterator01.php
$myArray has 3 elements
monkey: bananas
rabbit: carrots
ogre: onions
elem 2:rabbit: carrots
Execution time: 0.001346 microseconds.




                               18
Interfaces

•   Countable
    - provides an internal counter
•   SeekableIterator
    - provides an internal stack seeker


                             19
<?php
           Countable Example
//file: spl_countable01.php
class TequillaCounter implements Countable
{
    public function count()
    {
        static $count = 0;
        return ++$count;
    }

    public function order()
    {
        $order = $this->count();
        echo ($order > 3 ? quot;Floor!quot; : quot;{$order} tequillaquot;) . PHP_EOL;
    }
}




                                 20
Countable continued...
$shots = new TequillaCounter();
$shots->order();
$shots->order();
$shots->order();
$shots->order();

Output:
$ /usr/bin/php ./countable01.php
1 tequilla
2 tequilla
3 tequilla
Floor!




                                  21
SPL Exceptions
•   SPL Exceptions
    - templates
    - throw exceptions
    - common issues
•   Types of exceptions
    - LogicExceptions
    - RuntimeExceptions


                          22
SPL LogicException Tree




           23
SPL RuntimeException Tree




            24
<?php
           Exceptions Example
//file: spl_exception01.php
class MyClass
{
    public function giveANumberFromOneToTen($number)
    {
        if($number < 1 || $number > 10) {
            throw new OutOfBoundsException('Number should be between 1 and 10');
        }
        echo $number . PHP_EOL;
    }
}

$my = new MyClass();
try {
    $my->giveANumberFromOneToTen(5);
    $my->giveANumberFromOneToTen(20);
} catch (OutOfBoundsException $e) {
    echo $e->getMessage() . PHP_EOL;
}

Output:
$ /usr/bin/php ./spl_exception01.php
5
Number should be between 1 and 10




                                         25
SPL Functions
•   class_implements
    Return the interfaces which are implemented by the given class
•   class_parents
    Return the parent classes of the given class
•   iterator_apply
    Apply a user function to every element of an iterator
•   iterator_count
    Count the elements in an iterator
•   iterator_to_array
    Copy the iterator into an array
•   spl_autoload_call
    Try all registered __autoload() function to load requested class

                                 26
SPL Functions (2)
•   spl_autoload_functions
    Return all registered __autoload() functions
•   spl_autoload_register
    Register given function as __autoload() implementation
•   spl_autoload_unregister
    Unregister given function as __autoload() implementation
•   spl_autoload
    Default implementation for __autoload()
•   spl_classes
    Return available SPL classes
•   spl_object_hash
    Return hash id for given object

                                27
<?php
        SplFunctions Example
interface foo {}
interface bar {}

class baz implements foo, bar {}
class example extends baz {}

var_dump(class_implements(new baz));

var_dump(class_implements(new example));




                               28
Output of SplFunctions
array(2) {
  [quot;fooquot;]=>
  string(3)   quot;fooquot;
  [quot;barquot;]=>
  string(3)   quot;barquot;
}
array(2) {
  [quot;barquot;]=>
  string(3)   quot;barquot;
  [quot;fooquot;]=>
  string(3)   quot;fooquot;
}




                      29
SplFileInfo
•   SplFileInfo::__construct        •   SplFileInfo::getLinkTarget
•   SplFileInfo::getATime           •   SplFileInfo::getMTime
•   SplFileInfo::getBasename        •   SplFileInfo::getOwner
•   SplFileInfo::getCTime           •   SplFileInfo::getPath
•   SplFileInfo::getFileInfo        •   SplFileInfo::getPathInfo
•   SplFileInfo::getFilename        •   SplFileInfo::getPathname
•   SplFileInfo::getGroup           •   SplFileInfo::getPerms
•   SplFileInfo::getInode




                               30
SplFileInfo (2)
•   SplFileInfo::getRealPath         •   SplFileInfo::isReadable
•   SplFileInfo::getSize             •   SplFileInfo::isWritable
•   SplFileInfo::getType             •   SplFileInfo::openFile
•   SplFileInfo::isDir               •   SplFileInfo::setFileClass
•   SplFileInfo::isExecutable        •   SplFileInfo::setInfoClass
•   SplFileInfo::isFile              •   SplFileInfo::__toString
•   SplFileInfo::isLink




                                31
<?php
         SplFileInfo Example
// use the current file to get information from
$file = new SplFileInfo(dirname(__FILE__));

var_dump($file->isFile());
var_dump($file->getMTime());
var_dump($file->getSize());
var_dump($file->getFileInfo());
var_dump($file->getOwner());



//output
bool(false)
int(1244760945)
int(408)
object(SplFileInfo)#2 (0) {
}
int(501)


                                  32
Data Structures
•   Available in PHP 5.3.x

    -   SplDoublyLinkedList
        ✓ SplStack
        ✓ SplQueue
        ✓ SplHeap
        ✓ SplMaxHeap
        ✓ SplMinHeap
        ✓ SplPriorityQueue

                              33
Data Structures Example
<?php
// file: spl_stack01.php
$stack = new SplStack();
$stack->push('Message 1');
$stack->push('Message 2');
$stack->push('Message 3');

echo $stack->pop() . PHP_EOL;
echo $stack->pop() . PHP_EOL;
echo $stack->pop() . PHP_EOL;

Outputs:
$ /usr/bin/php ./spl_stack01.php
Message 3
Message 2
Message 1




                                34
Not a bridge too far...




           35
Conclusion


SPL can help you solve common PHP issues
        it’s built-in, so why not use it
   it requires no “advanced skills” to use




                    36
Only one minor thing...




           37
Documentation problem

•   php.net/spl needs more documentation !
•   you can help on that part:
    - see http://elizabethmariesmith.com/2009/02/setting-up-phd-on-windows
    - you can set up phpdoc on each platform !
    - Efnet: #php.doc channel
    - http://doc.php.net - phpdoc@php.net

                                    38
More about SPL...
•   main SPL documentation:
    http://php.net/spl
•   PHPro Tutorials on SPL:
    http://www.phpro.org/tutorials/Introduction-to-SPL.html
•   Lorenzo Alberton’s blog:
    http://www.alberton.info/php_5.3_spl_data_structures.html
•   http://www.colder.ch/news/01-08-2009/34/splobjectstorage-for-
    a-fa.html



                                39
License
This presentation is released under the Creative Commons
Attribution-Share Alike 3.0 Unported License
You are free:
- to share : to copy, distribute and transmit the work
- to remix : to adapt the work

Under the following conditions:
- attribution :You must attribute the work in the manner specified by the author or licensor
- share alike : If you alter, transform, or build upon this work, you may distribute the resulting work
only under the same, similar or a compatible license



See: http://creativecommons.org/licenses/by-sa/3.0/



                                                40
Credits


Golden Gate Bridge - Felix De Vliegher
http://www.flickr.com/photos/felixdv/2883471022/




                      41
Thank you

        Find my slides on
http://slideshare.net/DragonBe

    Don’t forget to vote !
     http://joind.in/586




            42

More Related Content

What's hot

Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
Lorna Mitchell
 
CLI, the other SAPI phpnw11
CLI, the other SAPI phpnw11CLI, the other SAPI phpnw11
CLI, the other SAPI phpnw11
Combell NV
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
Augusto Pascutti
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve
 
Cli the other sapi pbc11
Cli the other sapi pbc11Cli the other sapi pbc11
Cli the other sapi pbc11
Combell NV
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
Ricardo Signes
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
jsmith92
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
Nikita Popov
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
Fwdays
 
Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)
James Titcumb
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An
 
Call Return Exploration
Call Return ExplorationCall Return Exploration
Call Return Exploration
Pat Hawks
 
New in php 7
New in php 7New in php 7
New in php 7
Vic Metcalfe
 
Cli the other SAPI confoo11
Cli the other SAPI confoo11Cli the other SAPI confoo11
Cli the other SAPI confoo11
Combell NV
 
Calling Functions
Calling FunctionsCalling Functions
Calling Functions
Pat Hawks
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
Workhorse Computing
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
Lin Yo-An
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
Henry Osborne
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!
Boy Baukema
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
Andrew Shitov
 

What's hot (20)

Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
CLI, the other SAPI phpnw11
CLI, the other SAPI phpnw11CLI, the other SAPI phpnw11
CLI, the other SAPI phpnw11
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Cli the other sapi pbc11
Cli the other sapi pbc11Cli the other sapi pbc11
Cli the other sapi pbc11
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
 
Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
Call Return Exploration
Call Return ExplorationCall Return Exploration
Call Return Exploration
 
New in php 7
New in php 7New in php 7
New in php 7
 
Cli the other SAPI confoo11
Cli the other SAPI confoo11Cli the other SAPI confoo11
Cli the other SAPI confoo11
 
Calling Functions
Calling FunctionsCalling Functions
Calling Functions
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 

Similar to SPL, not a bridge too far

10 Catalyst Tips
10 Catalyst Tips10 Catalyst Tips
10 Catalyst Tips
Jay Shirley
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
Marcello Duarte
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
chartjes
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
elliando dias
 
Php 2
Php 2Php 2
Php 2
vivlinux
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Dhivyaa C.R
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
DrDhivyaaCRAssistant
 
What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?
Christophe Porteneuve
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascript
guest4d57e6
 
Bioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlBioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperl
Prof. Wim Van Criekinge
 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Michael Wales
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
Attila Balazs
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 
Intro to The PHP SPL
Intro to The PHP SPLIntro to The PHP SPL
Intro to The PHP SPL
Chris Tankersley
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
Michelangelo van Dam
 
PHP
PHP PHP
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Nate Abele
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
Aftabali702240
 

Similar to SPL, not a bridge too far (20)

10 Catalyst Tips
10 Catalyst Tips10 Catalyst Tips
10 Catalyst Tips
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Php 2
Php 2Php 2
Php 2
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
 
What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascript
 
Bioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlBioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperl
 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Intro to The PHP SPL
Intro to The PHP SPLIntro to The PHP SPL
Intro to The PHP SPL
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
PHP
PHP PHP
PHP
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
 

More from Michelangelo van Dam

GDPR Art. 25 - Privacy by design and default
GDPR Art. 25 - Privacy by design and defaultGDPR Art. 25 - Privacy by design and default
GDPR Art. 25 - Privacy by design and default
Michelangelo van Dam
 
Moving from app services to azure functions
Moving from app services to azure functionsMoving from app services to azure functions
Moving from app services to azure functions
Michelangelo van Dam
 
Privacy by design
Privacy by designPrivacy by design
Privacy by design
Michelangelo van Dam
 
DevOps or DevSecOps
DevOps or DevSecOpsDevOps or DevSecOps
DevOps or DevSecOps
Michelangelo van Dam
 
Privacy by design
Privacy by designPrivacy by design
Privacy by design
Michelangelo van Dam
 
Continuous deployment 2.0
Continuous deployment 2.0Continuous deployment 2.0
Continuous deployment 2.0
Michelangelo van Dam
 
Let your tests drive your code
Let your tests drive your codeLet your tests drive your code
Let your tests drive your code
Michelangelo van Dam
 
General Data Protection Regulation, a developer's story
General Data Protection Regulation, a developer's storyGeneral Data Protection Regulation, a developer's story
General Data Protection Regulation, a developer's story
Michelangelo van Dam
 
Leveraging a distributed architecture to your advantage
Leveraging a distributed architecture to your advantageLeveraging a distributed architecture to your advantage
Leveraging a distributed architecture to your advantage
Michelangelo van Dam
 
The road to php 7.1
The road to php 7.1The road to php 7.1
The road to php 7.1
Michelangelo van Dam
 
Open source for a successful business
Open source for a successful businessOpen source for a successful business
Open source for a successful business
Michelangelo van Dam
 
Decouple your framework now, thank me later
Decouple your framework now, thank me laterDecouple your framework now, thank me later
Decouple your framework now, thank me later
Michelangelo van Dam
 
Deploy to azure in less then 15 minutes
Deploy to azure in less then 15 minutesDeploy to azure in less then 15 minutes
Deploy to azure in less then 15 minutes
Michelangelo van Dam
 
Azure and OSS, a match made in heaven
Azure and OSS, a match made in heavenAzure and OSS, a match made in heaven
Azure and OSS, a match made in heaven
Michelangelo van Dam
 
Getting hands dirty with php7
Getting hands dirty with php7Getting hands dirty with php7
Getting hands dirty with php7
Michelangelo van Dam
 
Zf2 how arrays will save your project
Zf2   how arrays will save your projectZf2   how arrays will save your project
Zf2 how arrays will save your project
Michelangelo van Dam
 
Create, test, secure, repeat
Create, test, secure, repeatCreate, test, secure, repeat
Create, test, secure, repeat
Michelangelo van Dam
 
The Continuous PHP Pipeline
The Continuous PHP PipelineThe Continuous PHP Pipeline
The Continuous PHP Pipeline
Michelangelo van Dam
 
PHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the testsPHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the tests
Michelangelo van Dam
 
Easily extend your existing php app with an api
Easily extend your existing php app with an apiEasily extend your existing php app with an api
Easily extend your existing php app with an api
Michelangelo van Dam
 

More from Michelangelo van Dam (20)

GDPR Art. 25 - Privacy by design and default
GDPR Art. 25 - Privacy by design and defaultGDPR Art. 25 - Privacy by design and default
GDPR Art. 25 - Privacy by design and default
 
Moving from app services to azure functions
Moving from app services to azure functionsMoving from app services to azure functions
Moving from app services to azure functions
 
Privacy by design
Privacy by designPrivacy by design
Privacy by design
 
DevOps or DevSecOps
DevOps or DevSecOpsDevOps or DevSecOps
DevOps or DevSecOps
 
Privacy by design
Privacy by designPrivacy by design
Privacy by design
 
Continuous deployment 2.0
Continuous deployment 2.0Continuous deployment 2.0
Continuous deployment 2.0
 
Let your tests drive your code
Let your tests drive your codeLet your tests drive your code
Let your tests drive your code
 
General Data Protection Regulation, a developer's story
General Data Protection Regulation, a developer's storyGeneral Data Protection Regulation, a developer's story
General Data Protection Regulation, a developer's story
 
Leveraging a distributed architecture to your advantage
Leveraging a distributed architecture to your advantageLeveraging a distributed architecture to your advantage
Leveraging a distributed architecture to your advantage
 
The road to php 7.1
The road to php 7.1The road to php 7.1
The road to php 7.1
 
Open source for a successful business
Open source for a successful businessOpen source for a successful business
Open source for a successful business
 
Decouple your framework now, thank me later
Decouple your framework now, thank me laterDecouple your framework now, thank me later
Decouple your framework now, thank me later
 
Deploy to azure in less then 15 minutes
Deploy to azure in less then 15 minutesDeploy to azure in less then 15 minutes
Deploy to azure in less then 15 minutes
 
Azure and OSS, a match made in heaven
Azure and OSS, a match made in heavenAzure and OSS, a match made in heaven
Azure and OSS, a match made in heaven
 
Getting hands dirty with php7
Getting hands dirty with php7Getting hands dirty with php7
Getting hands dirty with php7
 
Zf2 how arrays will save your project
Zf2   how arrays will save your projectZf2   how arrays will save your project
Zf2 how arrays will save your project
 
Create, test, secure, repeat
Create, test, secure, repeatCreate, test, secure, repeat
Create, test, secure, repeat
 
The Continuous PHP Pipeline
The Continuous PHP PipelineThe Continuous PHP Pipeline
The Continuous PHP Pipeline
 
PHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the testsPHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the tests
 
Easily extend your existing php app with an api
Easily extend your existing php app with an apiEasily extend your existing php app with an api
Easily extend your existing php app with an api
 

Recently uploaded

Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 

Recently uploaded (20)

Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 

SPL, not a bridge too far

  • 1. SPL, not a bridge too far Dutch PHP Conference 2009 - Amsterdam
  • 2. Who am I ? Michelangelo van Dam Independent Enterprise PHP consultant @dragonbe http://dragonbe.com 2
  • 3. Who are you ? You know OOP ? You know php.net ? You know arrays ? 3
  • 4. What is SPL ? Standard PHP Library interfaces, classes and methods solve common development problems As of 5.3 SPL cannot be turned off from the source ! 4
  • 5. Why use SPL ? SPL provides a huge toolkit that assists you to easily iterate over a diversity of data structures in a standardized way 5
  • 6. What does it provide ? • ArrayObject - approach arrays as objects • Iterators - various iterators • Interfaces - Countable Interface • Exceptions - exceptions to streamline errorhandling • SPL Functions - extra functions and autoloader func • SplFileInfo - tools for filesystem access • Datastructures - structuring data sequences 6
  • 7. ArrayObject • provides an interface - treat arrays as objects - elements are iteratable 7
  • 8. ArrayObject methods • ArrayObject::append • ArrayObject::__construct • ArrayObject::count • ArrayObject::getIterator • ArrayObject::offsetExists • ArrayObject::offsetGet • ArrayObject::offsetSet • ArrayObject::offsetUnset 8
  • 9. <?php ArrayObject w/o SPL // file: nospl_arrayobject01.php $myArray = array ( quot;monkeyquot; => quot;bananasquot;, quot;rabbitquot; => quot;carrotsquot;, quot;ogrequot; => quot;onionsquot;, ); echo quot;Ogres exists ? quot; . (key_exists('ogre', $myArray) ? quot;Yesquot; : quot;Noquot;) . quot;nquot;; echo quot;Ogres equals quot; . $myArray['ogre'] . quot;nquot;; 9
  • 10. <?php ArrayObject Example // file: spl_arrayobject01.php $myArray = array ( quot;monkeyquot; => quot;bananasquot;, quot;rabbitquot; => quot;carrotsquot;, quot;ogrequot; => quot;onionsquot;, ); // create an object of the array $arrayObj = new ArrayObject($myArray); echo quot;Ogres exists ? quot; . ($arrayObj->offsetExists(quot;ogrequot;) ? quot;Yesquot; : quot;Noquot;) . quot;nquot;; echo quot;Ogres equals quot; . $arrayObj->offsetGet(quot;ogrequot;) . quot;nquot;; 10
  • 11. ArrayObject Output $ /usr/bin/php ./nospl_arrayobject01.php Ogres exists ? Yes Ogres equals onions Execution time: 0.00064299999999995 microseconds. $ /usr/bin/php ./spl_arrayobject01.php Ogres exists ? Yes Ogres equals onions Execution time: 0.00054399999999999 microseconds. 11
  • 12. Iterator • move back and forth in a stack • distinct methods to access keys and values 12
  • 13. Iterators • ArrayIterator • CachingIterator • RecursiveCachingIterator • DirectoryIterator • RecursiveDirectoryIterator • FilterIterator • LimitIterator • ParentIterator • RecursiveIteratorIterator 13
  • 14. The ArrayIterator iteration methods on array objects 14
  • 15. ArrayIterator Example Case • Array with 3 elements - monkey => bananas, - rabbit => carrots, - ogre => onions • display total elements • display key/value pairs while looping • display key/value pair for 2nd element 15
  • 16. <?php ArrayIterator w/o SPL // file: nospl_iterator01.php $myArray = array ( quot;monkeyquot; => quot;bananasquot;, quot;rabbitquot; => quot;carrotsquot;, quot;ogrequot; => quot;onionsquot;, ); echo quot;$myArray has {sizeof($myArray)} elementsnquot;; foreach ($myArray as $key => $value) { echo quot;{$key}: {$value}nquot;; } reset($myArray); next($myArray); echo quot;elem 2:quot; . key($myArray) . quot;: quot; . current($myArray) . quot;nquot;; 16
  • 17. <?php ArrayIterator w/ SPL // file: spl_iterator01.php $myArray = array ( “monkey” => “bananas”, “rabbit” => “carrots”, “ogre” => “onions”, ); $arrayObj = new ArrayObject($myArray); $iterator = $arrayObj->getIterator(); echo quot;$myArray has {$arrayObj->count()} elementsnquot;; while ($iterator->valid()) { echo quot;{$iterator->key()}: {$iterator->current()}nquot;; $iterator->next(); } $iterator->seek(1); echo quot;elem 2:{$iterator->key()}: {$iterator->current()}nquot;; 17
  • 18. ArrayIterator Output $ /usr/bin/php ./nospl_iterator01.php $myArray has 3 elements monkey: bananas rabbit: carrots ogre: onions elem 2:rabbit: carrots Execution time: 0.0020509999999999 microseconds. $ /usr/bin/php ./spl_iterator01.php $myArray has 3 elements monkey: bananas rabbit: carrots ogre: onions elem 2:rabbit: carrots Execution time: 0.001346 microseconds. 18
  • 19. Interfaces • Countable - provides an internal counter • SeekableIterator - provides an internal stack seeker 19
  • 20. <?php Countable Example //file: spl_countable01.php class TequillaCounter implements Countable { public function count() { static $count = 0; return ++$count; } public function order() { $order = $this->count(); echo ($order > 3 ? quot;Floor!quot; : quot;{$order} tequillaquot;) . PHP_EOL; } } 20
  • 21. Countable continued... $shots = new TequillaCounter(); $shots->order(); $shots->order(); $shots->order(); $shots->order(); Output: $ /usr/bin/php ./countable01.php 1 tequilla 2 tequilla 3 tequilla Floor! 21
  • 22. SPL Exceptions • SPL Exceptions - templates - throw exceptions - common issues • Types of exceptions - LogicExceptions - RuntimeExceptions 22
  • 25. <?php Exceptions Example //file: spl_exception01.php class MyClass { public function giveANumberFromOneToTen($number) { if($number < 1 || $number > 10) { throw new OutOfBoundsException('Number should be between 1 and 10'); } echo $number . PHP_EOL; } } $my = new MyClass(); try { $my->giveANumberFromOneToTen(5); $my->giveANumberFromOneToTen(20); } catch (OutOfBoundsException $e) { echo $e->getMessage() . PHP_EOL; } Output: $ /usr/bin/php ./spl_exception01.php 5 Number should be between 1 and 10 25
  • 26. SPL Functions • class_implements Return the interfaces which are implemented by the given class • class_parents Return the parent classes of the given class • iterator_apply Apply a user function to every element of an iterator • iterator_count Count the elements in an iterator • iterator_to_array Copy the iterator into an array • spl_autoload_call Try all registered __autoload() function to load requested class 26
  • 27. SPL Functions (2) • spl_autoload_functions Return all registered __autoload() functions • spl_autoload_register Register given function as __autoload() implementation • spl_autoload_unregister Unregister given function as __autoload() implementation • spl_autoload Default implementation for __autoload() • spl_classes Return available SPL classes • spl_object_hash Return hash id for given object 27
  • 28. <?php SplFunctions Example interface foo {} interface bar {} class baz implements foo, bar {} class example extends baz {} var_dump(class_implements(new baz)); var_dump(class_implements(new example)); 28
  • 29. Output of SplFunctions array(2) { [quot;fooquot;]=> string(3) quot;fooquot; [quot;barquot;]=> string(3) quot;barquot; } array(2) { [quot;barquot;]=> string(3) quot;barquot; [quot;fooquot;]=> string(3) quot;fooquot; } 29
  • 30. SplFileInfo • SplFileInfo::__construct • SplFileInfo::getLinkTarget • SplFileInfo::getATime • SplFileInfo::getMTime • SplFileInfo::getBasename • SplFileInfo::getOwner • SplFileInfo::getCTime • SplFileInfo::getPath • SplFileInfo::getFileInfo • SplFileInfo::getPathInfo • SplFileInfo::getFilename • SplFileInfo::getPathname • SplFileInfo::getGroup • SplFileInfo::getPerms • SplFileInfo::getInode 30
  • 31. SplFileInfo (2) • SplFileInfo::getRealPath • SplFileInfo::isReadable • SplFileInfo::getSize • SplFileInfo::isWritable • SplFileInfo::getType • SplFileInfo::openFile • SplFileInfo::isDir • SplFileInfo::setFileClass • SplFileInfo::isExecutable • SplFileInfo::setInfoClass • SplFileInfo::isFile • SplFileInfo::__toString • SplFileInfo::isLink 31
  • 32. <?php SplFileInfo Example // use the current file to get information from $file = new SplFileInfo(dirname(__FILE__)); var_dump($file->isFile()); var_dump($file->getMTime()); var_dump($file->getSize()); var_dump($file->getFileInfo()); var_dump($file->getOwner()); //output bool(false) int(1244760945) int(408) object(SplFileInfo)#2 (0) { } int(501) 32
  • 33. Data Structures • Available in PHP 5.3.x - SplDoublyLinkedList ✓ SplStack ✓ SplQueue ✓ SplHeap ✓ SplMaxHeap ✓ SplMinHeap ✓ SplPriorityQueue 33
  • 34. Data Structures Example <?php // file: spl_stack01.php $stack = new SplStack(); $stack->push('Message 1'); $stack->push('Message 2'); $stack->push('Message 3'); echo $stack->pop() . PHP_EOL; echo $stack->pop() . PHP_EOL; echo $stack->pop() . PHP_EOL; Outputs: $ /usr/bin/php ./spl_stack01.php Message 3 Message 2 Message 1 34
  • 35. Not a bridge too far... 35
  • 36. Conclusion SPL can help you solve common PHP issues it’s built-in, so why not use it it requires no “advanced skills” to use 36
  • 37. Only one minor thing... 37
  • 38. Documentation problem • php.net/spl needs more documentation ! • you can help on that part: - see http://elizabethmariesmith.com/2009/02/setting-up-phd-on-windows - you can set up phpdoc on each platform ! - Efnet: #php.doc channel - http://doc.php.net - phpdoc@php.net 38
  • 39. More about SPL... • main SPL documentation: http://php.net/spl • PHPro Tutorials on SPL: http://www.phpro.org/tutorials/Introduction-to-SPL.html • Lorenzo Alberton’s blog: http://www.alberton.info/php_5.3_spl_data_structures.html • http://www.colder.ch/news/01-08-2009/34/splobjectstorage-for- a-fa.html 39
  • 40. License This presentation is released under the Creative Commons Attribution-Share Alike 3.0 Unported License You are free: - to share : to copy, distribute and transmit the work - to remix : to adapt the work Under the following conditions: - attribution :You must attribute the work in the manner specified by the author or licensor - share alike : If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license See: http://creativecommons.org/licenses/by-sa/3.0/ 40
  • 41. Credits Golden Gate Bridge - Felix De Vliegher http://www.flickr.com/photos/felixdv/2883471022/ 41
  • 42. Thank you Find my slides on http://slideshare.net/DragonBe Don’t forget to vote ! http://joind.in/586 42

Editor's Notes

  1. Promotion of SPL
  2. Definition of SPL
  3. SPL functions - base class functions - autoloading functions