Slide 1

Slide 1 text

PHP 5.3 OVERVIEW 6/8/2010 - Dallas PHP Jake Smith

Slide 2

Slide 2 text

PERFORMANCE • Over 140 bug fixes • 40%+ improvement with PHP on Windows • 5% - 15% overall performance improvement • MD5 roughly 15% faster • Constants move to read-only memory • Drupal 20% faster, Wordpress 15% faster

Slide 3

Slide 3 text

ADDITIONS • New error_reporting E_DEPRECATED • Garbage collection • MySQLnd (Native Driver) • No longer uses libmysql • No PDO support (currently) • MySQL version 4.1+

Slide 4

Slide 4 text

BACKWARDS COMPATIBILITY • EREG Family is now E_DEPRECATED • Use the Pearl Compatible (PCRE) • __toString does not accept arguments/parameters • Magic methods must be public and can not be static • __call is now invoked on access to private/protected methods • Classes can not be named Namespace or Closure SOURCES: http://us2.php.net/manual/en/migration53.incompatible.php

Slide 5

Slide 5 text

MAGIC METHODS IN 5.3 \n"; } private function __get($method) { } private function __set($method, $value) { } private function getElements() { echo "Get Elements
\n"; } } $bc = new Backwards(); $bc->getElements();

Slide 6

Slide 6 text

CHANGES IN PHP.INI • INI Variables • Per Folder/Per Site ini settings • User specified ini files

Slide 7

Slide 7 text

.INI VARIABLES error_dev = E_ALL error_prod = E_NONE [HOST=dev.mydomain.com] error_reporting = ${error_dev} [HOST=mydomain.com] error_reporting = ${error_prod} [PATH=/var/www/vhosts/myotherdomain.com] error_reporting = ${error_prod} # User Defined ini. Place in web root. Set to blank to disable user_ini.filename = .user.ini user_ini.cache_ttl = 300

Slide 8

Slide 8 text

SLOW ADOPTION • Open Source projects were initially not compatible with PHP 5.3 • Currently most major Open Source software (Wordpress, Drupal, Joomla and Magento) work in PHP 5.3 • Key plugins are lacking behind

Slide 9

Slide 9 text

PECL ADDITIONS • PECL Added • FileInfo, Intl, Phar, MySQLnd, SQLite3 • PECL Removed • ncurses, FPDF, dbase, fbsql, ming SOURCES: http://php.net/releases/5_3_0.php

Slide 10

Slide 10 text

SPL ADDITIONS • GlobIterator - Iterator utilizing glob, look up glob function • SplFixedArray - Fixed size/dimension array • SplQueue • SplHeap • SplStack SOURCES: http://matthewturland.com/2010/05/20/new-spl-features-in-php-5-3/

Slide 11

Slide 11 text

NEW CONSTANTS • __DIR__ • No more dirname(__FILE__); • __NAMESPACE__ • Current namespace

Slide 12

Slide 12 text

NEW OPERATORS • Ternary Operator ?: • Goto • NOWDOC

Slide 13

Slide 13 text

TERNARY OPERATOR

Slide 14

Slide 14 text

GOTO SOURCES: http://xkcd.com/292/

Slide 15

Slide 15 text

GOTO EXAMPLE

Slide 16

Slide 16 text

NOWDOC VS. HEREDOC • NOWDOC works just like HEREDOC, except it does not evaluate PHP variables

Slide 17

Slide 17 text

DATE/TIME OBJECT ADDITIONS • New functions/methods added to Date/Time Object • date_add, date_sub and date_diff SOURCES: http://www.php.net/manual/en/class.datetime.php add(new DateInterval('P10D')); echo $date->format('Y-m-d') . "\n"; // OR $date = date_create('200-01-01'); date_add($date, date_interval_create_from_date_string('10 days')); echo date_format($date, 'Y-m-d');

Slide 18

Slide 18 text

NEW METHODS • Functors/__invoke • Dynamic Static Method • __callStatic • get_called_class()

Slide 19

Slide 19 text

__INVOKE

Slide 20

Slide 20 text

DYNAMIC STATIC METHOD $method($criteria, $order, $limit, $offset); } }

Slide 21

Slide 21 text

DYNAMIC STATIC METHOD

Slide 22

Slide 22 text

__CALLSTATIC • __callStatic works exactly like __call, except it’s a static method • Acts as a catch all for all undefined methods (get or set)

Slide 23

Slide 23 text

GET_CLASS_CALLED • get_called_class returns the class name that called on the parent method

Slide 24

Slide 24 text

GET_CLASS_CALLED

Slide 25

Slide 25 text

LATE STATIC BINDING • This feature was named "late static bindings" with an internal perspective in mind. "Late binding" comes from the fact that static:: will no longer be resolved using the class where the method is defined but it will rather be computed using runtime information. SOURCES: http://us.php.net/lsb

Slide 26

Slide 26 text

LSB BEFORE PHP 5.3

Slide 27

Slide 27 text

LSB PHP 5.3.X • static keyword to save the day!

Slide 28

Slide 28 text

LAMBDA IN PHP 5.3 • Anonymous functions, also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of callback parameters, but they have many other uses. • Good function examples: array_map() and array_walk()

Slide 29

Slide 29 text

LAMBDA EXAMPLE (JQUERY) $('.button').click(function() { $(this).hide(); });

Slide 30

Slide 30 text

CLOSURE '; echo $rowColor() . '
'; echo $rowColor() . '
'; echo $rowColor() . '
'; echo $rowColor() . '
'; echo $rowColor() . '
';

Slide 31

Slide 31 text

NAMESPACES • Before PHP 5.3 • PHP didn’t have namespaces, so we created a standard: “Zend_Auth_Adapter_DbTable” • PEAR naming convention • Easier for autoloaders

Slide 32

Slide 32 text

DEFINING A NAMESPACE

Slide 33

Slide 33 text

“USE” A NAMESPACE formatPhone('123-456-7890')) { echo 'ITS TRUE'; }

Slide 34

Slide 34 text

DEFINING MULTIPLE NAMESPACES

Slide 35

Slide 35 text

WHAT IS GLOBAL SCOPE? • Global Scope is your “root level” outside of the namespace getConnection();

Slide 36

Slide 36 text

ORM EXAMPLE 0) { list($order, $limit, $offset) = $params; } $method = $matches[1]; return static::$method($criteria, $order, $limit, $offset); } public static function find($criteria = array(), $order = null, $limit = null, $offset = 0) { echo static::TABLE_NAME; echo $order . ' ' . $limit . ' ' . $offset; } } } namespace App\Models { class Posts extends \App\Model { const TABLE_NAME = 'posts'; } }

Slide 37

Slide 37 text

QUESTIONS?

Slide 38

Slide 38 text

THANKS FOR LISTENING Contact Information [t]: @jakefolio [e]: [email protected] [w]: http://www.jakefolio.com