Share
Embed
PHP 5.3
Presentation given at Austin, Texas for English360 - Cambridge
Mariano Iglesias
September 24, 2010
Transcript
19 slides
-
PHP 5.3 PHP 5.3 The “ The “OMG it's finally
here OMG it's finally here” release ” release -
PHP 5.3 is... PHP 5.3 is... • 1.2 times faster
than PHP 5.2 1.2 times faster than PHP 5.2 • 3.5 times faster than PHP 5.0 3.5 times faster than PHP 5.0 • 4.5 times faster than PHP 4 4.5 times faster than PHP 4 • 29.25 times faster than PHP 3 29.25 times faster than PHP 3 WTF times 2!! WTF is this doing here? -
So? Don't Hello World me! So? Don't Hello World me!
• Against PHP 5.2: Against PHP 5.2: – Drupal: 30% faster Drupal: 30% faster – Typo3: 30% faster Typo3: 30% faster – Wordpress: 15% faster Wordpress: 15% faster – E360: I don't know, let's ask E360: I don't know, let's ask Diego Diego -
Bottom line Bottom line • PHP 5.3 is PHP 5.3
is faster faster! ! – Ruby fans, deal with it Ruby fans, deal with it P.S: Could be much faster with Lighty, or NGiNX, just sayin' -
Ok so PHP 5.3 is fast Ok so PHP 5.3
is fast That's boring... Let's move on to the That's boring... Let's move on to the fun fun stuff stuff -
Can I hear some drum rolls? Can I hear some
drum rolls? no /play drums in open office :( -
Circular reference cleaning Circular reference cleaning • For frameworks, that's
like what TIVO did for TV For frameworks, that's like what TIVO did for TV • Or like what Facebook did for stalking ex girlfriends Or like what Facebook did for stalking ex girlfriends • Or even what Or even what GIT GIT did for source code collaboration did for source code collaboration PS 1: Notice how subtle I was to introduce GIT PS 2: I should also point out how Apple is not in this list -
How does this unbelievably new and so How does this
unbelievably new and so unheard of magic work, really? unheard of magic work, really? • Ok so variables are zval Ok so variables are zval – Real variables Real variables – References through References through refCount refCount $a = 'Linux rocks'; $b = $a; xdebug_debug_zval($a); unset($b); xdebug_debug_zval($a); $c = &$a; xdebug_debug_zval($c); a: (refcount=2, is_ref=0)='Linux rocks' a: (refcount=1, is_ref=0)='Linux rocks' a: (refcount=1, is_ref=1)='Linux rocks' I'm not ashamed to say it: I want to marry xdebug -
Namespaces Namespaces All hail the separator All hail the separator
\ I'm sure a JAVA dev is having a heart attack right now -
Thou shalt organize thy code Thou shalt organize thy code
namespace e360\acme class AwfulClass { public function __construct() { throw new \Exception(“Your code never works”); } } $sucks = new \e360\acme\AwfulClass(); echo get_class($sucks); → e360\acme\AwfulClass -
Late static binding Late static binding PHP 5.2: PHP 5.2:
self self: Not right! Mariano sad : Not right! Mariano sad class Repository { public static function commit() { static::_doIt(); } protected static function _doIt() { echo 'SVN commit :('; } } class GIT extends Repository { protected static function _doIt() { echo 'GIT commit :)'; } } GIT::commit(); → SVN commit :( PHP 5.3: PHP 5.3: static static: Yay! Mariano happy! : Yay! Mariano happy! → GIT commit :) -
The OMG factor The OMG factor • Ladies and gentleman,
let me introduce you to: Ladies and gentleman, let me introduce you to: – Lambdas Lambdas – Closures Closures -
Lambdas Lambdas $lines = array_filter( explode(“\n”, file_get_contents('developers.txt')), function ($line) {
$line = explode(',', $line); return ($line[1] != 'CDC'); } ); Closures Closures function getDevs($byeByeCompany = 'CDC') { return array_filter( explode(“\n”, file_get_contents('developers.txt')), function ($line) use($company) { $line = explode(',', $line); return ($line[1] != $byeByeCompany); } ); } -
As if all that wasn't enough... As if all that
wasn't enough... • ?: operator ?: operator • mysqlnd mysqlnd • phar phar require_once('phar:///home/www/e360/git.phar/switch.php'); $div = $options['div'] ?: false; -
The future (PHP 5.4) The future (PHP 5.4) • Yeah,
Unicode created a whole discussion regarding PHP 6 Yeah, Unicode created a whole discussion regarding PHP 6 • But already in trunk... But already in trunk... TRAITS TRAITS!! !! -
Traits Traits • Multiple inheritance? NOP Multiple inheritance? NOP •
Interfaces? NOP Interfaces? NOP • What is it then? What is it then? Horizontal Horizontal reuse reuse … … Say What? Say What? -
trait e360Serializer { protected function serialize() { // ... }
protected function deserialize() { // .... } } class Item extends AppModel { use e360Serializer; // ... } class ItemPdf extends Item { use e360JSONSerializer; public function serializable() { return true; } // ... } trait e360JSONSerializer { use e360Serializer; protected function serialize() { // ... } protected function deserialize() { // .... } abstract public function serializable(); }