php 5.3, a walkthrough

74
PHP 5.3 A Walkthrough @davidcoallier Dé Luain 20 Meán Fómhair 2010

Upload: david-coallier

Post on 13-Apr-2017

2.819 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: PHP 5.3, a walkthrough

PHP 5.3A Walkthrough

@davidcoallier

Dé Luain 20 Meán Fómhair 2010

Page 2: PHP 5.3, a walkthrough

Who are you?Experiences, usage, etc.

Dé Luain 20 Meán Fómhair 2010

Page 3: PHP 5.3, a walkthrough

Who am I?Work, experiences, usage, etc.

Dé Luain 20 Meán Fómhair 2010

Page 4: PHP 5.3, a walkthrough

The Talk!Recap of why you are here...

Dé Luain 20 Meán Fómhair 2010

Page 5: PHP 5.3, a walkthrough

A small PHP 6Oh no, you didn’t!

Dé Luain 20 Meán Fómhair 2010

Page 6: PHP 5.3, a walkthrough

In a nutshellmysqlnd, phar, syntax, sqlite3, spl-sauce, speed, etc.

Dé Luain 20 Meán Fómhair 2010

Page 7: PHP 5.3, a walkthrough

ext/intlInternationalization Extension

Dé Luain 20 Meán Fómhair 2010

Page 8: PHP 5.3, a walkthrough

Collatorstring comparison, sorting, locale

Dé Luain 20 Meán Fómhair 2010

Page 9: PHP 5.3, a walkthrough

Numbers...1,000,000; 1.000.000; 1 000 000

Dé Luain 20 Meán Fómhair 2010

Page 10: PHP 5.3, a walkthrough

ICU☃☕♨♿⚛

Dé Luain 20 Meán Fómhair 2010

Page 11: PHP 5.3, a walkthrough

More Importantly

Dé Luain 20 Meán Fómhair 2010

Page 12: PHP 5.3, a walkthrough

L S BLate Static Binding, wtf is that?

Dé Luain 20 Meán Fómhair 2010

Page 13: PHP 5.3, a walkthrough

NAMESPACES\\\\

Dé Luain 20 Meán Fómhair 2010

Page 14: PHP 5.3, a walkthrough

NAMESPACES!!!!

Dé Luain 20 Meán Fómhair 2010

Page 15: PHP 5.3, a walkthrough

Closures & λs

Dé Luain 20 Meán Fómhair 2010

Page 16: PHP 5.3, a walkthrough

Late-Static Bindingself:: vs static::, what’s that? LSB?

Dé Luain 20 Meán Fómhair 2010

Page 17: PHP 5.3, a walkthrough

class Base { public static function who() { echo __CLASS__; } public static function foo() { self::who(); }}

class Child extends Base { public static function who() { echo __CLASS__; }}

Child::foo(); // Echoes Base

Dé Luain 20 Meán Fómhair 2010

Page 18: PHP 5.3, a walkthrough

class Base { public static function who() { echo __CLASS__; } public static function foo() { static::who(); }}

class Child extends Base { public static function who() { echo __CLASS__; }}

Child::foo(); // Echoes Child

Dé Luain 20 Meán Fómhair 2010

Page 19: PHP 5.3, a walkthrough

$this is not static::Don’t get tricked, no inheritance

Dé Luain 20 Meán Fómhair 2010

Page 20: PHP 5.3, a walkthrough

Object LifecycleCreate, Immute, Memoize

Dé Luain 20 Meán Fómhair 2010

Page 21: PHP 5.3, a walkthrough

Referencial TransparencyIt’s not maths, it’s software.

Dé Luain 20 Meán Fómhair 2010

Page 22: PHP 5.3, a walkthrough

ZzzZz.....

Dé Luain 20 Meán Fómhair 2010

Page 23: PHP 5.3, a walkthrough

Dynamic StaticsOh that sounds nasty...

Dé Luain 20 Meán Fómhair 2010

Page 24: PHP 5.3, a walkthrough

$class = 'ClassName';$method = 'methodName';

$class::$method(...);

Dé Luain 20 Meán Fómhair 2010

Page 25: PHP 5.3, a walkthrough

Remember __call?

Dé Luain 20 Meán Fómhair 2010

Page 26: PHP 5.3, a walkthrough

__callStatic()

Dé Luain 20 Meán Fómhair 2010

Page 27: PHP 5.3, a walkthrough

Enough Statics..Moving on.

Dé Luain 20 Meán Fómhair 2010

Page 28: PHP 5.3, a walkthrough

NamespacesSo we have namespaces, now what?

Dé Luain 20 Meán Fómhair 2010

Page 29: PHP 5.3, a walkthrough

\Get over it.\We know. \

Dé Luain 20 Meán Fómhair 2010

Page 30: PHP 5.3, a walkthrough

OrganizeStructural decisions, maintainability

Dé Luain 20 Meán Fómhair 2010

Page 31: PHP 5.3, a walkthrough

namespace pear\package;class Example { // ...}

Dé Luain 20 Meán Fómhair 2010

Page 32: PHP 5.3, a walkthrough

use pear\package;$class = new Example();// or$class = new pear\package\Example();

Dé Luain 20 Meán Fómhair 2010

Page 33: PHP 5.3, a walkthrough

MeaningAnd community significance

Dé Luain 20 Meán Fómhair 2010

Page 34: PHP 5.3, a walkthrough

The culprit\strlen

Dé Luain 20 Meán Fómhair 2010

Page 35: PHP 5.3, a walkthrough

Coding Standardshttp://groups.google.com/group/php-standards/web/psr-0-final-proposal

Dé Luain 20 Meán Fómhair 2010

Page 36: PHP 5.3, a walkthrough

PharThe jar-like PHP Archives

Dé Luain 20 Meán Fómhair 2010

Page 37: PHP 5.3, a walkthrough

include 'phar://package.phar/index.php';

Dé Luain 20 Meán Fómhair 2010

Page 38: PHP 5.3, a walkthrough

$phar = new Phar('drupal7.phar');$phar->buildFromDirectory(__DIR__ . '/drupal7');$phar->setStub("<?phpPhar::interceptFileFuncs();Phar::webPhar();__HALT_COMPILER(); ?>"

Dé Luain 20 Meán Fómhair 2010

Page 39: PHP 5.3, a walkthrough

RewriteRule ^(.*)$ /drupal7.phar/$1 [QSA,L]

Dé Luain 20 Meán Fómhair 2010

Page 40: PHP 5.3, a walkthrough

Running, web-ing Phar magic-happy-times.

Dé Luain 20 Meán Fómhair 2010

Page 41: PHP 5.3, a walkthrough

λ (Lambda)Assigned to a variable

Dé Luain 20 Meán Fómhair 2010

Page 42: PHP 5.3, a walkthrough

$name = function() { return 'david'; };

Dé Luain 20 Meán Fómhair 2010

Page 43: PHP 5.3, a walkthrough

Closurefunctions with bound variables

Dé Luain 20 Meán Fómhair 2010

Page 44: PHP 5.3, a walkthrough

$names = array( 'Nate Abele', 'David Coallier', 'Cap\'n Crunch' ); $split = array_map( function($name) { list($first, $last) = explode(' ', $name); return compact('first', 'last'); }, $names ); // Result: array( array('first' => 'Nate', 'last' => 'Abele'), array('first' => 'David', 'last' => 'Coallier'), array('first' => 'Cap\'n', 'last' => 'Crunch') )

Stolen From NATE!

Dé Luain 20 Meán Fómhair 2010

Page 45: PHP 5.3, a walkthrough

$names = array('david', 'nate');$friends = array('helgi', 'joel');

$split = function($name) use ($friends) { //...};

Dé Luain 20 Meán Fómhair 2010

Page 46: PHP 5.3, a walkthrough

Functors :O

Dé Luain 20 Meán Fómhair 2010

Page 47: PHP 5.3, a walkthrough

class Name { public function __invoke() { return 'david'; }}

echo $name();

Dé Luain 20 Meán Fómhair 2010

Page 48: PHP 5.3, a walkthrough

Other things?SPL, changes, NOWDOCS, etc

Dé Luain 20 Meán Fómhair 2010

Page 49: PHP 5.3, a walkthrough

Fast TernariesNo need to check anymore... Beware

Dé Luain 20 Meán Fómhair 2010

Page 50: PHP 5.3, a walkthrough

$name = isset($_GET['name']) ? $_GET['name'] : 'No Name';

Dé Luain 20 Meán Fómhair 2010

Page 51: PHP 5.3, a walkthrough

$name = $_GET['name'] ?: 'No Name';

Dé Luain 20 Meán Fómhair 2010

Page 52: PHP 5.3, a walkthrough

NOWDOCSNOWDOCS cooler than HEREDOCS

Dé Luain 20 Meán Fómhair 2010

Page 53: PHP 5.3, a walkthrough

$name = 'david';$example =<<<RTFMHello $name,See you soon.RTFM;// Hello David

Dé Luain 20 Meán Fómhair 2010

Page 54: PHP 5.3, a walkthrough

$name = 'david';$example =<<<'RTFM'Hello $name,See you soon.RTFM;// Hello $name

Dé Luain 20 Meán Fómhair 2010

Page 55: PHP 5.3, a walkthrough

PerformanceBetter faster strong. Better stack

Dé Luain 20 Meán Fómhair 2010

Page 56: PHP 5.3, a walkthrough

Garbage Collectiongc_enable(), gc_disable(), etc.

Dé Luain 20 Meán Fómhair 2010

Page 57: PHP 5.3, a walkthrough

__DIR__dirname(__FILE__)

Dé Luain 20 Meán Fómhair 2010

Page 58: PHP 5.3, a walkthrough

__NAMESPACE__

Dé Luain 20 Meán Fómhair 2010

Page 59: PHP 5.3, a walkthrough

namespace pear\package\Example2 { const TEST = 'In Namespaces...'; function foo() { echo __NAMESPACE__; }}

echo \pear\package\Example2::TEST; // In Namespaces...\pear\package\Example2\foo(); // Example2

Dé Luain 20 Meán Fómhair 2010

Page 60: PHP 5.3, a walkthrough

E_DEPRECATED

Dé Luain 20 Meán Fómhair 2010

Page 61: PHP 5.3, a walkthrough

MySQLndNative MySQL Driver, faster, stats, self-contained

Dé Luain 20 Meán Fómhair 2010

Page 62: PHP 5.3, a walkthrough

DateTimeCrazy amazing dates handling

Dé Luain 20 Meán Fómhair 2010

Page 63: PHP 5.3, a walkthrough

$datetime1 = new DateTime('2009-10-11');$datetime2 = new DateTime('2009-10-13');$interval = $datetime1->diff($datetime2);

echo $interval->format('%R%d days');

// +2 days

Dé Luain 20 Meán Fómhair 2010

Page 64: PHP 5.3, a walkthrough

SPLIterators, Iterators, Iterators.

Dé Luain 20 Meán Fómhair 2010

Page 65: PHP 5.3, a walkthrough

SPLDatastructures, Exceptions, Misc...

Dé Luain 20 Meán Fómhair 2010

Page 66: PHP 5.3, a walkthrough

My Favourite

Dé Luain 20 Meán Fómhair 2010

Page 67: PHP 5.3, a walkthrough

PHP FPMAlternate FastCGI Implementation 5.3.3

Dé Luain 20 Meán Fómhair 2010

Page 68: PHP 5.3, a walkthrough

IncentiveWhy do I have to use PHP 5.3?

Dé Luain 20 Meán Fómhair 2010

Page 69: PHP 5.3, a walkthrough

LithiumIt’s so rad!

Dé Luain 20 Meán Fómhair 2010

Page 70: PHP 5.3, a walkthrough

Zend Framework 2

Dé Luain 20 Meán Fómhair 2010

Page 71: PHP 5.3, a walkthrough

Symfony 2

Dé Luain 20 Meán Fómhair 2010

Page 72: PHP 5.3, a walkthrough

Doctrine 2

Dé Luain 20 Meán Fómhair 2010

Page 73: PHP 5.3, a walkthrough

Q&A

Dé Luain 20 Meán Fómhair 2010

Page 74: PHP 5.3, a walkthrough

Thank you@davidcoallier

Dé Luain 20 Meán Fómhair 2010