php 5.4 - begin your love affair with traits

Download PHP 5.4 - Begin your love affair with traits

If you can't read please download the document

Post on 14-May-2015

16.014 views

Category:

Technology

0 download

Embed Size (px)

DESCRIPTION

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

TRANSCRIPT

  • 1.PHP 5.4Begin your love affair with Traits- Graham Weldon

2. Graham WeldonPHP developer since... foreverCakePHP contributor/ evangelistSerial conference speakerGaming enthusiastBeer drinkerhttp://grahamweldon.comhttp://cakedc.comhttp://cakephp.orgTwitter: @predominant 3. SydPHPWeve got awesome stuff coming upVisit us! http://sydphp.orgNovember MeetupDecember Phunconference 2January Australia Day BBQ 4. What PHP Version?PHP 4PHP 5.1PHP 5.2PHP 5.3PHP 5.4PHP 6 (Yes, there are some people using it) 5. 1007550 25PHP 3PHP 4 0PHP 5PHP 6 Data courtesy of w3techs.com 6. 80 60 40205.05.1 5.2 05.3 5.4Data courtesy of w3techs.com 7. Traditionally slow adoptersPHP 4 to PHP 5 was a painfully slow upgrade for theglobal communityShared hosts retained old versionsObject handling was differentPHP 5.1 on CentOSPeople dont upgrade stable systemsPHP 5.2 massive exposureAgain, people dont upgrade stable systemsPHP 5.3 used, but not fully 8. Why slow adopters?Shared hostsEstablished applicationsUpgrade pathOld excuses 9. Why adopt early?New language featuresMore elegant ways to solve problemsCleaner codeAdopting early gets you noticed 10. What about instability?Be sensible with production-ready systemsDont use the bleeding edgeConrm functionalityUnit TestingIntegration testingLoad testingIf your tests pass, then phase in the new systemUse sensible reporting / monitoring 11. Enter PHP 5.4 (RC1) 12. PHP 5.4-RC1RC1 was released for QA on 11th November 2011Some new features, plenty of bug xesYou can download it for yourself!http://qa.php.net/Give it a trySee if your applications run on it 13. PHP 5.4New Language Featuresand Improvements 14. Upload Progress 15. Binary Notation! 16. Array short syntaxhttps://wiki.php.net/rfc/shortsyntaxforarrays 17. Array dereferencinghttps://wiki.php.net/rfc/functionarraydereferencing 18. Class member accesson instantiation 19. Closures (Current) 20. Closures (Array)https://wiki.php.net/rfc/indirect-method-call-by-array-var 21. But this doesnt work... :-( 22. Closures and $thishttps://wiki.php.net/rfc/closures/object-extension 23. Callable Typehinthttps://wiki.php.net/rfc/callable 24. JsonSerializable Interface 25. Short Tag echo - Always available 26. Oh, and there is a built-inweb server now. Yay? 27. https://wiki.php.net/ 28. PHP Traits 29. Whats the big deal?Elegant code re-useWithout complicated multiple inheritanceNo diamond issuesKinda like interfacesBut provides implementationOther languages are doing similar thingsPHP is keeping up with the trends 30. A look atGolang interfaces 31. PHPs approachTraits dene small sections of reusable codeThis code can be included in any classThere is a loading precedence orderPuts developers in controlLooks a feels naturalNo need to write things twiceOverride capabilities 32. PHP TraitsExample 33. PHP TraitsExample 34. PHP TraitsReal Example 35. SometimesTraits needAdjustmentMaybe log() needs tobe public in youruse case. 36. ChangeMethodsas you likelog() is now accessibleto the User instancein this context. 37. CustomiseFurtherChange method namesif youre into thatsort of thing.Provide preferences. 38. Graham Weldon Twitter: @predominant http://grahamweldon.com Its over! http://cakedc.comQuestions? http://cakephp.org Get in touch if you want to know more about this presentation, PHP in general, or anything. :-)