Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

New Wave PHP

Slide 3

Slide 3 text

New Wave PHP

Slide 4

Slide 4 text

New Wave PHP

Slide 5

Slide 5 text

New Shiny

Slide 6

Slide 6 text

Magic DIR Constant (5.3) Instead of: dirname(__FILE__); Now you can use: __DIR__;

Slide 7

Slide 7 text

Anonymous Functions (5.3) Declare a function in the place where it is used. (you may have seen this in JavaScript)

Slide 8

Slide 8 text

Anonymous Functions The old way: $things = array("name" => "Alice", "colour" => "Blue", "origin" => "Dreams"); function formatit($value, $key) { echo $key . ": " . $value . "\n"; } array_walk($things, "formatit");

Slide 9

Slide 9 text

Anonymous Functions Using an anonymous function: $things = array("name" => "Alice", "colour" => "Blue", "origin" => "Dreams"); array_walk($things, function ($value, $key) { echo $key . ": " . $value . "\n"; });

Slide 10

Slide 10 text

Namespaces (5.3) Namespaces are for combining libraries in one project. • we keep our own code in its own namespace(s) • we can pick-and-mix other people's code • class names don't have crazy long prefixes • combined with PSR standards, they enable Composer

Slide 11

Slide 11 text

Namespaced Library File namespace Lorna; class Nonsense { protected $words = array("wibble", "squeak", "howl", "pop"); public function speak() { return $this->words[ array_rand($this->words)]; } }

Slide 12

Slide 12 text

Namespaced Calling Code include 'lorna/nonsense.php'; use Lorna\Nonsense; $nsense = new Nonsense(); echo $nsense->speak(); $other = new \StdClass();

Slide 13

Slide 13 text

PHP's Own Webserver (5.4) php -S localhost:8080

Slide 14

Slide 14 text

PHP's Own Webserver php -S dev.project.local:8080 -t /var/www/cool-project/web -c php-ini.development routing.php

Slide 15

Slide 15 text

Short Array Notation (5.4) Three sets of equivalent notation: $game = array(0 => 'stone', 1 => 'paper', 2 => 'scissors'); $game[0] = 'paper'; $game[1] = 'scissors'; $game[2] = 'stone'; $game = [0 => 'scissors', 1 => 'stone', 2 => 'paper'];

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Array Dereferencing (5.4) function getList() { return ['Grumpy', 'Sleepy', 'Bashful', 'Doc']; } // grab first item from list $item = getList()[0]; echo $item;

Slide 18

Slide 18 text

Echo Shortcut (5.4) PHP 5.4 removes short_open_tag config option •

Slide 19

Slide 19 text

Echo Shortcut

A template saying "hi, "

Could also be written as:

A template saying "hi, "

Slide 20

Slide 20 text

Session Upload Progress File upload progress, written to the session at intervals Useful for user feedback, e.g. shiny progress bars!

Slide 21

Slide 21 text

Tracking Upload Progress User starts uploading file in the usual way " value="123" /> File:

Slide 22

Slide 22 text

Tracking Upload Progress In a separate file, we can check the relevant session variables to see how the upload is going: http://lrnja.net/Lhs7jJ Array(1) { ["upload_progress_123"]=> array(5) { ["start_time"]=> int(1340542011) ["content_length"]=> int(1529158981) ["bytes_processed"]=> int(1386660589) ["done"]=> bool(false) ["files"]=> array(1) { ... } } }

Slide 23

Slide 23 text

Less Nonsense (5.4) Removed in PHP 5.4: • register_globals • register_long_arrays • safe_mode • magic_quotes • allow_call_time_pass_reference • y2k_compliance • ereg* functions

Slide 24

Slide 24 text

Easy Password Hashing (5.5) $pass = "secretpassword"; $hashed = password_hash($pass, PASSWORD_DEFAULT); echo $hashed; $2y$10$Q7Rm.Cmcu4lbvI7.C2q4Z.1LLoh4C63vBSfflQtfjs

Slide 25

Slide 25 text

Easy Password Hashing $existing_hash = '$2y$10$Q7Rm.Cmcu4lbvI7.C2q4Z.1LLoh4C $pass = "secretpassword"; if(password_verify($pass, $existing_hash)) echo "All good"; else echo "Go away"; For PHP < 5.5: http://github.com/ircmaxell/password_compat

Slide 26

Slide 26 text

Built-in OpCache (5.5) Replaces APC - beware this is disabled by default. Turn on opcache.enable and opcache.enable_cli

Slide 27

Slide 27 text

Upgrading An Existing System

Slide 28

Slide 28 text

Performance Comparison

Slide 29

Slide 29 text

How To Upgrade 1. Turn on E_DEPRECATED on your current platform and watch the logs (PHP 5.3+) 2. Compile PHP and run test suite with target version 3. Run application with PHP's webserver (PHP 5.4+) 4. Upgrade a test/staging platform 5. Go for it

Slide 30

Slide 30 text

Finding Platforms New projects should be PHP 5.5 or later. Questions to ask: • What versions of PHP are available? • Are backups included? • Which extensions are available, and can I add others? • Can I get support with my PHP setup?

Slide 31

Slide 31 text

Unofficial List of Providers • Servergrove http://www.servergrove.com/ • Linode https://www.linode.com/ • Digital Ocean https://www.digitalocean.com/ • Siteground http://www.siteground.com/ • Rackspace http://rackspace.com

Slide 32

Slide 32 text

Drupal 8 and the Future

Slide 33

Slide 33 text

Come to the Future

Slide 34

Slide 34 text

Come to the Future PHP now has: • even better features • great tools • improved performance • a rich future with tools like Drupal built on it

Slide 35

Slide 35 text

Questions? (and resources) Intermediate PHP http://lrnja.net/php-video Contact me: @lornajane or http://lornajane.net

Slide 36

Slide 36 text

No content