SlideShare a Scribd company logo
1 of 38
Download to read offline
PHP 5.4
Begin your love affair with Traits

- Graham Weldon
Graham Weldon
PHP developer since... forever

CakePHP contributor/ evangelist

Serial conference speaker

Gaming enthusiast

Beer drinker



http://grahamweldon.com

http://cakedc.com

http://cakephp.org

Twitter: @predominant
SydPHP
We’ve got awesome stuff coming up

Visit us! http://sydphp.org



November Meetup

December “Phunconference 2”

January Australia Day BBQ
What PHP Version?

  PHP 4

  PHP 5.1

  PHP 5.2

  PHP 5.3

  PHP 5.4

  PHP 6 (Yes, there are some people using it)
100




                                        75




                                      50




                                   25


PHP 3
        PHP 4                     0
                PHP 5
                        PHP 6

   Data courtesy of w3techs.com
80




                                           60




                                         40




                                      20


5.0
        5.1
               5.2                   0
                      5.3
                             5.4

      Data courtesy of w3techs.com
Traditionally slow adopters

  PHP 4 to PHP 5 was a painfully slow upgrade for the
  global community

      Shared hosts retained old versions

      Object handling was different

  PHP 5.1 on CentOS

      People don’t upgrade stable systems

  PHP 5.2 massive exposure

      Again, people don’t upgrade stable systems

  PHP 5.3 used, but not fully
Why slow adopters?

  Shared hosts

  Established applications

  Upgrade path



  Old excuses
Why adopt early?

  New language features

  More elegant ways to solve problems

  Cleaner code

  Adopting early gets you noticed
What about instability?

  Be sensible with production-ready systems

  Don’t use the bleeding edge

  Confirm functionality

      Unit Testing

      Integration testing

      Load testing

  If your tests pass, then phase in the new system

  Use sensible reporting / monitoring
Enter PHP 5.4 (RC1)
PHP 5.4-RC1

  RC1 was released for QA on 11th November 2011

  Some new features, plenty of bug fixes



  You can download it for yourself!

  http://qa.php.net/



  Give it a try

  See if your applications run on it
PHP 5.4
New Language Features
  and Improvements
Upload Progress
Binary Notation!
Array short syntax
https://wiki.php.net/rfc/shortsyntaxforarrays
Array dereferencing
https://wiki.php.net/rfc/functionarraydereferencing
Class member access
  on instantiation
Closures (Current)
Closures (Array)
https://wiki.php.net/rfc/indirect-method-call-by-array-var
But this doesn’t work...   :-(
Closures and ‘$this’
https://wiki.php.net/rfc/closures/object-extension
Callable Typehint
https://wiki.php.net/rfc/callable
JsonSerializable Interface
Short Tag echo - Always available
Oh, and there is a built-in
web server now. Yay?
https://wiki.php.net/
PHP Traits
Whats the big deal?

  Elegant code re-use

  Without complicated multiple inheritance

      No diamond issues

  Kinda like interfaces

  But provides implementation

  Other languages are doing similar things

  PHP is keeping up with the trends
A look at
Golang interfaces
PHP’s approach

  Traits define small sections of reusable code

  This code can be included in any class

  There is a loading precedence order

      Puts developers in control

  Looks a feels natural

  No need to write things twice

  Override capabilities
PHP Traits
Example
PHP Traits
Example
PHP Traits
Real Example
Sometimes
Traits need
Adjustment
Maybe log() needs to
be public in your
use case.
Change
Methods
as you like
log() is now accessible
to the User instance
in this context.
Customise
Further
Change method names
if you’re into that
sort of thing.

Provide preferences.
Graham Weldon

             Twitter: @predominant



             http://grahamweldon.com


 Its over!   http://cakedc.com


Questions?   http://cakephp.org




             Get in touch if you want to
             know more about this
             presentation, PHP in
             general, or anything. :-)

More Related Content

What's hot

Moving Pictures - Web 2.0 Expo NYC
Moving Pictures - Web 2.0 Expo NYCMoving Pictures - Web 2.0 Expo NYC
Moving Pictures - Web 2.0 Expo NYC
Cal Henderson
 
Coldfusion
ColdfusionColdfusion
Coldfusion
Ram
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
DanWooster1
 

What's hot (20)

Moving Pictures - Web 2.0 Expo NYC
Moving Pictures - Web 2.0 Expo NYCMoving Pictures - Web 2.0 Expo NYC
Moving Pictures - Web 2.0 Expo NYC
 
2021laravelconftwslides6
2021laravelconftwslides62021laravelconftwslides6
2021laravelconftwslides6
 
An introduction to Titanium
An introduction to TitaniumAn introduction to Titanium
An introduction to Titanium
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
 
Coldfusion
ColdfusionColdfusion
Coldfusion
 
mod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLImod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLI
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
 
Composer - The missing package manager for PHP
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHP
 
CPAN Dependency Heaven
CPAN Dependency HeavenCPAN Dependency Heaven
CPAN Dependency Heaven
 
Perl
PerlPerl
Perl
 
Modern Perl for the Unfrozen Paleolithic Perl Programmer
Modern Perl for the Unfrozen Paleolithic  Perl ProgrammerModern Perl for the Unfrozen Paleolithic  Perl Programmer
Modern Perl for the Unfrozen Paleolithic Perl Programmer
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHP
 
A look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architectureA look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architecture
 
Pinto+Stratopan+Love
Pinto+Stratopan+LovePinto+Stratopan+Love
Pinto+Stratopan+Love
 
Scalable PHP
Scalable PHPScalable PHP
Scalable PHP
 
Modern Perl for the Unfrozen Paleolithic Perl Programmer
Modern Perl for the Unfrozen Paleolithic Perl ProgrammerModern Perl for the Unfrozen Paleolithic Perl Programmer
Modern Perl for the Unfrozen Paleolithic Perl Programmer
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:winConsole Apps: php artisan forthe:win
Console Apps: php artisan forthe:win
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
 
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
 

Viewers also liked

SydPHP May 2012 - Deployment
SydPHP May 2012 - DeploymentSydPHP May 2012 - Deployment
SydPHP May 2012 - Deployment
Graham Weldon
 

Viewers also liked (7)

SydPHP May 2012 - Deployment
SydPHP May 2012 - DeploymentSydPHP May 2012 - Deployment
SydPHP May 2012 - Deployment
 
Re-imagining CakePHP (OSDC 2010)
Re-imagining CakePHP (OSDC 2010)Re-imagining CakePHP (OSDC 2010)
Re-imagining CakePHP (OSDC 2010)
 
SydPHP April 2012
SydPHP April 2012SydPHP April 2012
SydPHP April 2012
 
The business behind open source
The business behind open sourceThe business behind open source
The business behind open source
 
CakePHP and Open Source - Newcastle University
CakePHP and Open Source - Newcastle UniversityCakePHP and Open Source - Newcastle University
CakePHP and Open Source - Newcastle University
 
Building 3D apps with Javascript
Building 3D apps with JavascriptBuilding 3D apps with Javascript
Building 3D apps with Javascript
 
traitを使って楽したい話
traitを使って楽したい話traitを使って楽したい話
traitを使って楽したい話
 

Similar to PHP 5.4 - Begin your love affair with traits

2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real
PHP Conference Argentina
 
PHP - History, Introduction, Summary, Extensions and Frameworks
PHP - History, Introduction, Summary, Extensions and FrameworksPHP - History, Introduction, Summary, Extensions and Frameworks
PHP - History, Introduction, Summary, Extensions and Frameworks
Royston Olivera
 
introduction to web programming using PHP
introduction to web programming using PHPintroduction to web programming using PHP
introduction to web programming using PHP
vishnupriyapm4
 
Applied+Web+Development+[Autosaved].pptx
Applied+Web+Development+[Autosaved].pptxApplied+Web+Development+[Autosaved].pptx
Applied+Web+Development+[Autosaved].pptx
voot1
 
Federico Feroldi: PHP in Yahoo!
Federico Feroldi: PHP in Yahoo!Federico Feroldi: PHP in Yahoo!
Federico Feroldi: PHP in Yahoo!
Francesco Fullone
 
Slides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetingsSlides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetings
10n Software, LLC
 

Similar to PHP 5.4 - Begin your love affair with traits (20)

Php7
Php7Php7
Php7
 
Professional PHP: an open-source alternative for enterprise development [Antw...
Professional PHP: an open-source alternative for enterprise development [Antw...Professional PHP: an open-source alternative for enterprise development [Antw...
Professional PHP: an open-source alternative for enterprise development [Antw...
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHP
 
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real
 
PHP
PHPPHP
PHP
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8
 
PHP - History, Introduction, Summary, Extensions and Frameworks
PHP - History, Introduction, Summary, Extensions and FrameworksPHP - History, Introduction, Summary, Extensions and Frameworks
PHP - History, Introduction, Summary, Extensions and Frameworks
 
Webdevcon pierrejoye-php54-and-other
Webdevcon pierrejoye-php54-and-otherWebdevcon pierrejoye-php54-and-other
Webdevcon pierrejoye-php54-and-other
 
introduction to web programming using PHP
introduction to web programming using PHPintroduction to web programming using PHP
introduction to web programming using PHP
 
Applied+Web+Development+[Autosaved].pptx
Applied+Web+Development+[Autosaved].pptxApplied+Web+Development+[Autosaved].pptx
Applied+Web+Development+[Autosaved].pptx
 
Php intro
Php introPhp intro
Php intro
 
Integrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIntegrating PHP With System-i using Web Services
Integrating PHP With System-i using Web Services
 
CakePHP 3.0: Embracing the future
CakePHP 3.0: Embracing the futureCakePHP 3.0: Embracing the future
CakePHP 3.0: Embracing the future
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
 
Federico Feroldi: PHP in Yahoo!
Federico Feroldi: PHP in Yahoo!Federico Feroldi: PHP in Yahoo!
Federico Feroldi: PHP in Yahoo!
 
Federico Feroldi Php In Yahoo
Federico Feroldi Php In YahooFederico Feroldi Php In Yahoo
Federico Feroldi Php In Yahoo
 
PHPNW Test Fest Pre-presentation
PHPNW Test Fest Pre-presentationPHPNW Test Fest Pre-presentation
PHPNW Test Fest Pre-presentation
 
PHP LICTURES ..........
PHP LICTURES ..........PHP LICTURES ..........
PHP LICTURES ..........
 
Slides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetingsSlides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetings
 
Wp Presentation
Wp PresentationWp Presentation
Wp Presentation
 

More from Graham Weldon

20130714 php matsuri - highly available php
20130714   php matsuri - highly available php20130714   php matsuri - highly available php
20130714 php matsuri - highly available php
Graham Weldon
 

More from Graham Weldon (9)

HackLang Introduction
HackLang IntroductionHackLang Introduction
HackLang Introduction
 
20130714 php matsuri - highly available php
20130714   php matsuri - highly available php20130714   php matsuri - highly available php
20130714 php matsuri - highly available php
 
SydPHP June 2012 - GovHack overview
SydPHP June 2012 - GovHack overviewSydPHP June 2012 - GovHack overview
SydPHP June 2012 - GovHack overview
 
MySQL Performance - SydPHP October 2011
MySQL Performance - SydPHP October 2011MySQL Performance - SydPHP October 2011
MySQL Performance - SydPHP October 2011
 
Nginx in production
Nginx in productionNginx in production
Nginx in production
 
CakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your worldCakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your world
 
CakePHP Tutorial - OSDC 2010
CakePHP Tutorial - OSDC 2010CakePHP Tutorial - OSDC 2010
CakePHP Tutorial - OSDC 2010
 
Debugging and Profiling PHP
Debugging and Profiling PHPDebugging and Profiling PHP
Debugging and Profiling PHP
 
OSDC LIghtning Talk - Context Free Art
OSDC LIghtning Talk - Context Free ArtOSDC LIghtning Talk - Context Free Art
OSDC LIghtning Talk - Context Free Art
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

PHP 5.4 - Begin your love affair with traits