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