Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
PHP 5.4
Begin your love affair with Traits

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

CakePHP contributor/ evangelist

Serial conference speaker

Gaming enthusias...
SydPHP
We’ve got awesome stuff coming up

Visit us! http://sydphp.org



November Meetup

December “Phunconference 2”

Jan...
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




                      ...
80




                                           60




                                         40




                 ...
Traditionally slow adopters

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

      Shared hosts ...
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 yo...
What about instability?

  Be sensible with production-ready systems

  Don’t use the bleeding edge

  Confirm functionalit...
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 downloa...
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 l...
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 loa...
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...
Upcoming SlideShare
Loading in …5
×

of

PHP 5.4 - Begin your love affair with traits Slide 1 PHP 5.4 - Begin your love affair with traits Slide 2 PHP 5.4 - Begin your love affair with traits Slide 3 PHP 5.4 - Begin your love affair with traits Slide 4 PHP 5.4 - Begin your love affair with traits Slide 5 PHP 5.4 - Begin your love affair with traits Slide 6 PHP 5.4 - Begin your love affair with traits Slide 7 PHP 5.4 - Begin your love affair with traits Slide 8 PHP 5.4 - Begin your love affair with traits Slide 9 PHP 5.4 - Begin your love affair with traits Slide 10 PHP 5.4 - Begin your love affair with traits Slide 11 PHP 5.4 - Begin your love affair with traits Slide 12 PHP 5.4 - Begin your love affair with traits Slide 13 PHP 5.4 - Begin your love affair with traits Slide 14 PHP 5.4 - Begin your love affair with traits Slide 15 PHP 5.4 - Begin your love affair with traits Slide 16 PHP 5.4 - Begin your love affair with traits Slide 17 PHP 5.4 - Begin your love affair with traits Slide 18 PHP 5.4 - Begin your love affair with traits Slide 19 PHP 5.4 - Begin your love affair with traits Slide 20 PHP 5.4 - Begin your love affair with traits Slide 21 PHP 5.4 - Begin your love affair with traits Slide 22 PHP 5.4 - Begin your love affair with traits Slide 23 PHP 5.4 - Begin your love affair with traits Slide 24 PHP 5.4 - Begin your love affair with traits Slide 25 PHP 5.4 - Begin your love affair with traits Slide 26 PHP 5.4 - Begin your love affair with traits Slide 27 PHP 5.4 - Begin your love affair with traits Slide 28 PHP 5.4 - Begin your love affair with traits Slide 29 PHP 5.4 - Begin your love affair with traits Slide 30 PHP 5.4 - Begin your love affair with traits Slide 31 PHP 5.4 - Begin your love affair with traits Slide 32 PHP 5.4 - Begin your love affair with traits Slide 33 PHP 5.4 - Begin your love affair with traits Slide 34 PHP 5.4 - Begin your love affair with traits Slide 35 PHP 5.4 - Begin your love affair with traits Slide 36 PHP 5.4 - Begin your love affair with traits Slide 37 PHP 5.4 - Begin your love affair with traits Slide 38
Upcoming SlideShare
SydPHP March 2012 Meetup
Next
Download to read offline and view in fullscreen.

24 Likes

Share

Download to read offline

PHP 5.4 - Begin your love affair with traits

Download to read offline

Slides for my talk at OSDC PHP MiniConf. November 14, 2011.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

PHP 5.4 - Begin your love affair with traits

  1. 1. PHP 5.4 Begin your love affair with Traits - Graham Weldon
  2. 2. 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
  3. 3. SydPHP We’ve got awesome stuff coming up Visit us! http://sydphp.org November Meetup December “Phunconference 2” January Australia Day BBQ
  4. 4. 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)
  5. 5. 100 75 50 25 PHP 3 PHP 4 0 PHP 5 PHP 6 Data courtesy of w3techs.com
  6. 6. 80 60 40 20 5.0 5.1 5.2 0 5.3 5.4 Data courtesy of w3techs.com
  7. 7. 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
  8. 8. Why slow adopters? Shared hosts Established applications Upgrade path Old excuses
  9. 9. Why adopt early? New language features More elegant ways to solve problems Cleaner code Adopting early gets you noticed
  10. 10. 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
  11. 11. Enter PHP 5.4 (RC1)
  12. 12. 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
  13. 13. PHP 5.4 New Language Features and Improvements
  14. 14. Upload Progress
  15. 15. Binary Notation!
  16. 16. Array short syntax https://wiki.php.net/rfc/shortsyntaxforarrays
  17. 17. Array dereferencing https://wiki.php.net/rfc/functionarraydereferencing
  18. 18. Class member access on instantiation
  19. 19. Closures (Current)
  20. 20. Closures (Array) https://wiki.php.net/rfc/indirect-method-call-by-array-var
  21. 21. But this doesn’t work... :-(
  22. 22. Closures and ‘$this’ https://wiki.php.net/rfc/closures/object-extension
  23. 23. Callable Typehint https://wiki.php.net/rfc/callable
  24. 24. JsonSerializable Interface
  25. 25. Short Tag echo - Always available
  26. 26. Oh, and there is a built-in web server now. Yay?
  27. 27. https://wiki.php.net/
  28. 28. PHP Traits
  29. 29. 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
  30. 30. A look at Golang interfaces
  31. 31. 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
  32. 32. PHP Traits Example
  33. 33. PHP Traits Example
  34. 34. PHP Traits Real Example
  35. 35. Sometimes Traits need Adjustment Maybe log() needs to be public in your use case.
  36. 36. Change Methods as you like log() is now accessible to the User instance in this context.
  37. 37. Customise Further Change method names if you’re into that sort of thing. Provide preferences.
  38. 38. 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. :-)
  • AkiraMiki

    Jan. 2, 2013
  • tomokioosaki

    Sep. 27, 2012
  • makies

    May. 24, 2012
  • yasu00000

    May. 9, 2012
  • diovanemonteiro

    Feb. 20, 2012
  • jaguarnet7

    Feb. 15, 2012
  • ayumimizoshiri

    Feb. 14, 2012
  • izuno

    Feb. 2, 2012
  • dataich

    Feb. 1, 2012
  • yandod

    Jan. 31, 2012
  • mahmudur1

    Jan. 22, 2012
  • ShahnoorChowdhury

    Jan. 22, 2012
  • takuya

    Dec. 8, 2011
  • nojimage

    Nov. 29, 2011
  • TakeshiWatanabe2

    Nov. 23, 2011
  • tanakahisateru

    Nov. 22, 2011
  • invent

    Nov. 22, 2011
  • akihito.koriyama

    Nov. 22, 2011
  • KosukeHorii

    Nov. 17, 2011
  • ShunsukeKotani

    Nov. 17, 2011

Slides for my talk at OSDC PHP MiniConf. November 14, 2011.

Views

Total views

18,439

On Slideshare

0

From embeds

0

Number of embeds

7,079

Actions

Downloads

250

Shares

0

Comments

0

Likes

24

×