Transcript
Page 1: PHP 5.4 - Begin your love affair with traits

PHP 5.4Begin your love affair with Traits

- Graham Weldon

Page 2: PHP 5.4 - Begin your love affair with traits

Graham WeldonPHP developer since... forever

CakePHP contributor/ evangelist

Serial conference speaker

Gaming enthusiast

Beer drinker

http://grahamweldon.com

http://cakedc.com

http://cakephp.org

Twitter: @predominant

Page 3: PHP 5.4 - Begin your love affair with traits

SydPHPWe’ve got awesome stuff coming up

Visit us! http://sydphp.org

November Meetup

December “Phunconference 2”

January Australia Day BBQ

Page 4: PHP 5.4 - Begin your love affair with traits

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)

Page 5: PHP 5.4 - Begin your love affair with traits

0

25

50

75

100

PHP 3PHP 4

PHP 5PHP 6

Data courtesy of w3techs.com

Page 6: PHP 5.4 - Begin your love affair with traits

0

20

40

60

80

5.0 5.1 5.25.3

5.4

Data courtesy of w3techs.com

Page 7: PHP 5.4 - Begin your love affair with traits

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

Traditionally slow adopters

Page 8: PHP 5.4 - Begin your love affair with traits

Why slow adopters?

Shared hosts

Established applications

Upgrade path

Old excuses

Page 9: PHP 5.4 - Begin your love affair with traits

Why adopt early?

New language features

More elegant ways to solve problems

Cleaner code

Adopting early gets you noticed

Page 10: PHP 5.4 - Begin your love affair with traits

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

Page 11: PHP 5.4 - Begin your love affair with traits

Enter PHP 5.4 (RC1)

Page 12: PHP 5.4 - Begin your love affair with traits

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

Page 13: PHP 5.4 - Begin your love affair with traits

PHP 5.4New Language Features

and Improvements

Page 14: PHP 5.4 - Begin your love affair with traits

Upload Progress

Page 15: PHP 5.4 - Begin your love affair with traits

Binary Notation!

Page 16: PHP 5.4 - Begin your love affair with traits

Array short syntaxhttps://wiki.php.net/rfc/shortsyntaxforarrays

Page 17: PHP 5.4 - Begin your love affair with traits

Array dereferencinghttps://wiki.php.net/rfc/functionarraydereferencing

Page 18: PHP 5.4 - Begin your love affair with traits

Class member accesson instantiation

Page 19: PHP 5.4 - Begin your love affair with traits

Closures (Current)

Page 20: PHP 5.4 - Begin your love affair with traits

Closures (Array)https://wiki.php.net/rfc/indirect-method-call-by-array-var

Page 21: PHP 5.4 - Begin your love affair with traits

But this doesn’t work... :-(

Page 22: PHP 5.4 - Begin your love affair with traits

Closures and ‘$this’https://wiki.php.net/rfc/closures/object-extension

Page 23: PHP 5.4 - Begin your love affair with traits

Callable Typehinthttps://wiki.php.net/rfc/callable

Page 24: PHP 5.4 - Begin your love affair with traits

JsonSerializable Interface

Page 25: PHP 5.4 - Begin your love affair with traits

Short Tag echo - Always available

Page 26: PHP 5.4 - Begin your love affair with traits

Oh, and there is a built-inweb server now. Yay?

Page 27: PHP 5.4 - Begin your love affair with traits

https://wiki.php.net/

Page 28: PHP 5.4 - Begin your love affair with traits

PHP Traits

Page 29: PHP 5.4 - Begin your love affair with 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

Page 30: PHP 5.4 - Begin your love affair with traits

A look atGolang interfaces

Page 31: PHP 5.4 - Begin your love affair with traits

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

Page 32: PHP 5.4 - Begin your love affair with traits

PHP TraitsExample

Page 33: PHP 5.4 - Begin your love affair with traits

PHP TraitsExample

Page 34: PHP 5.4 - Begin your love affair with traits

PHP TraitsReal Example

Page 35: PHP 5.4 - Begin your love affair with traits

SometimesTraits needAdjustmentMaybe log() needs tobe public in youruse case.

Page 36: PHP 5.4 - Begin your love affair with traits

ChangeMethodsas you likelog() is now accessibleto the User instancein this context.

Page 37: PHP 5.4 - Begin your love affair with traits

CustomiseFurtherChange method namesif you’re into thatsort of thing.

Provide preferences.

Page 38: PHP 5.4 - Begin your love affair with traits

Its over!Questions?

Graham Weldon

Twitter: @predominant

http://grahamweldon.com

http://cakedc.com

http://cakephp.org

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


Top Related