The PHP 5.4 Features You Will Actually Use



Similar documents
Working with forms in PHP

PHP Tutorial From beginner to master

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

<?php if (Login::isLogged(Login::$_login_front)) { Helper::redirect(Login::$_dashboard_front); }

Chapter 22 How to send and access other web sites

TCP/IP Networking, Part 2: Web-Based Control

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

There are numerous ways to access monitors:

PHP Authentication Schemes

Forms, CGI Objectives. HTML forms. Form example. Form example...

Web Services Tutorial

GTPayment Merchant Integration Manual

Recommended readings. Lecture 11 - Securing Web. Applications. Security. Declarative Security

Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

Facebook Twitter YouTube Google Plus Website

Writing Scripts with PHP s PEAR DB Module

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Major Subject

By : Ashish Modi. CRUD USING PHP (Create, Read, Update and Delete on Database) Create Database and Table using following Sql Syntax.

XML Processing and Web Services. Chapter 17

PHP Form Handling. Prof. Jim Whitehead CMPS 183 Spring 2006 May 3, 2006

PHP Debugging. Draft: March 19, Christopher Vickery

Certified PHP Developer VS-1054

Web Programming with PHP 5. The right tool for the right job.

An Introduction to Developing ez Publish Extensions

RESTful web applications with Apache Sling

A table is a collection of related data entries and it consists of columns and rows.

MERCHANT INTEGRATION GUIDE. Version 2.8

JavaScript Basics & HTML DOM. Sang Shin Java Technology Architect Sun Microsystems, Inc. sang.shin@sun.com

InPost UK Limited GeoWidget Integration Guide Version 1.1

FORM-ORIENTED DATA ENTRY

Form Mail Tutorial. Introduction. The cgi-bin

ARC: appmosphere RDF Classes for PHP Developers

Web development... the server side (of the force)

PHP Integration Kit. Version User Guide

WHMCS Integration Manual

Ansible. Configuration management tool and ad hoc solution. Marcel Nijenhof

Internet Technologies

By Glenn Fleishman. WebSpy. Form and function

Contents. 2 Alfresco API Version 1.0

2- Forms and JavaScript Course: Developing web- based applica<ons

Web Development using PHP (WD_PHP) Duration 1.5 months

07 Forms. 1 About Forms. 2 The FORM Tag. 1.1 Form Handlers

Building Rich Internet Applications with PHP and Zend Framework

Fermilab Central Web Service Site Owner User Manual. DocDB: CS-doc-5372

Dynamic Web-Enabled Data Collection

Content Management System

Designing for Dynamic Content

App Central: Developer's Guide. For APKG 2.0

Online signature API. Terms used in this document. The API in brief. Version 0.20,

Why Use Zend Framework?

Chapter 2: Interactive Web Applications

CGI Programming. What is CGI?

A Tour of Silex and Symfony Components. Robert

Secure Application Development with the Zend Framework

Lesson 7 - Website Administration

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

CERTIFIED MULESOFT DEVELOPER EXAM. Preparation Guide

Advanced PostgreSQL SQL Injection and Filter Bypass Techniques

HTML Forms. Pat Morin COMP 2405

An Introduction to Drupal Architecture. John VanDyk DrupalCamp Des Moines, Iowa September 17, 2011

Web Development 1 A4 Project Description Web Architecture

LICENSE4J AUTO LICENSE GENERATION AND ACTIVATION SERVER USER GUIDE

Drupal and ArcGIS Yes, it can be done. Frank McLean Developer

Install Apache on windows 8 Create your own server

DEERFIELD.COM. DNS2Go Update API. DNS2Go Update API

Sonatype CLM for Maven. Sonatype CLM for Maven

Data Management Applications with Drupal as Your Framework

IceWarp Server - SSO (Single Sign-On)

Specialized Programme on Web Application Development using Open Source Tools

Script Handbook for Interactive Scientific Website Building

Configuring the Bundled SESM RADIUS Server

Develop PHP mobile apps with Zend Framework

s sent to the FaxFinder fax server must meet the following criteria to be processed for sending as a fax:

Part II of The Pattern to Good ILE. with RPG IV. Scott Klement

ez Publish Extension for Oracle(R) database 2.0 ez Publish Extension Manual

Dove User Guide Copyright Virgil Trasca

Art of Code Front-end Web Development Training Program

SuiteCRM for Developers

Log Analyzer Reference

A REST API for Arduino & the CC3000 WiFi Chip

Installation Documentation Smartsite ixperion 1.3

Web Programming Step by Step

CAIL Security Facility NSK Host to Host FTP Encryption

Tutorial 6 Creating a Web Form. HTML and CSS 6 TH EDITION

WIRIS quizzes web services Getting started with PHP and Java

Assignment 3 Version 2.0 Reactive NoSQL Due April 13

phpservermon Documentation

Introduction to Ingeniux Forms Builder. 90 minute Course CMSFB-V6 P

Flexible Routing and Load Control on Back-End Servers. Controlling the Request Load and Quality of Service

CS412 Interactive Lab Creating a Simple Web Form

A Comparative Study on Vega-HTTP & Popular Open-source Web-servers

Motivation retaining redisplaying

phpmyadmin Documentation

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

Microsoft Windows PowerShell v2 For Administrators

Transcription:

The PHP 5.4 Features You Will Actually Use

About Me Lorna Jane Mitchell PHP Consultant/Developer Author of PHP Master Twitter: @lornajane Website: http://lornajane.net 2

About PHP 5.4 New features Traits Built-in webserver New array syntax And more! Removed some nonsense This talk covers the best bits* * an entirely subjective selection 3

Start With The Easy Bit

New Array Syntax

Array Syntax We had this: $game[] = 'paper'; $game[] = 'scissors'; $game[] = 'stone'; print_r($game); $game[0] = 'paper'; $game[1] = 'scissors'; $game[2] = 'stone'; print_r($game); 6

Array Syntax Or this: $game = array('stone', 'paper', 'scissors'); print_r($game); $game = array(0 => 'stone', 1 => 'paper', 2 => 'scissors'); print_r($game); 7

Array Syntax Now we can do: $game = ['scissors', 'stone', 'paper']; print_r($game); $game = [0 => 'scissors', 1 => 'stone', 2 => 'paper']; print_r($game); 8

PHP 5.4 Stealth Feature

PHP 5.4 Is Faster

PHP Versions Speed Comparison Benchmarks made using: Newly-compiled vanilla PHP binaries The bench.php script in the PHP source tree A rather average laptop 10 runs per version, then averaged 11

PHP Versions Speed Comparison 12

PHP Versions Speed Comparison 13

PHP Versions Speed Comparison 14

PHP Versions Speed Comparison 15

Traits

Traits Re-usable groups of methods, in languages with single inheritance. Declare a trait, it looks like a class Add the trait to your class using the use keyword Methods are available! 17

Simplest Trait Example <?php trait Audit { public function getaudittrail() { return "nothing changed"; } } class Princess { use Audit; } // General princess class description: // soldering, tree climbing, the usual $daisy = new Princess(); echo $daisy->getaudittrail(); 18

Other Trait Trivia They can be aliased when used There are rules about resolving naming clashes Traits can include properties Traits can include abstract methods Traits can themselves make use of other traits 19

Built In Webserver

Built In Webserver Built in application server for PHP 5.4 Simple Lightweight Development use only From the manual: "Requests are served sequentially." http://lrnja.net/nqoxsh 21

Webserver Examples Start a simple server on a port number of your choice php -S localhost:8080 http://localhost:8080 22

Webserver Examples Change the hostname: php -S dev.project.local:8080 http://dev.project.local:8080 23

Webserver Examples Specify the docroot php -S localhost:8080 -t /var/www/superproject Specify which php.ini to use (default: none) php -S localhost:8080 -c php.ini-development 24

Webserver Examples Use a routing file (example from http://lrnja.net/ligi4u) <?php if (file_exists( DIR. '/'. $_SERVER['REQUEST_URI'])) { return false; // serve the requested resource as-is } else { include_once 'index.php'; } routing.php php -S localhost:8080 routing.php The webserver runs routing.php before entering the requested script. This example serves any existing resource, or routes to index.php 25

Session Upload Progress

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

Tracking Upload Progress User starts uploading file in the usual way <form name="upload" method="post" enctype="multipart/form-data"> <input type="hidden" name="<?php echo ini_get("session.upload_progress.name");?>" value="123" /> File: <input type="file" id="file1" name="file1" /> <input type="submit" value="start upload" /> </form> 28

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) { [0]=> array(7) {... } } } } 29

Callable Typehint

Typehinting We can typehint in PHP, on: Classes Interfaces Arrays 31

Typehinting We can typehint in PHP, on: Classes Interfaces Arrays... and now Callable Callable denotes anything that can be called - e.g. a closure, callback or invokable object 31

Callable Examples $ping = function() { echo "ping!"; }; $pong = "pong"; function sparkles(callable $func) { $func(); return "fairy dust"; } echo sparkles($ping); // ping!fairy dust echo sparkles($pong); Catchable fatal error: Argument 1 passed to sparkles() must be callable, string given, called in /home/lorna/.../callable.php on line 16 and defined in /home/lorna/.../callable.php on line 10 32

Callable Examples function sparkles(callable $func) { $func(); return "fairy dust"; } class Butterfly { public function invoke() { echo "flutter"; } } $bee = new Butterfly(); echo sparkles($bee); // flutterfairy dust 33

JsonSerializable

Sleep and Wakeup When we serialize() or unserialize() an object, PHP provides "magic methods" for us to hook into (this isn t new): sleep() to specify which fields should be serialized wakeup() to perform any operations needed to complete an object when it is unserialized This gives us the same feature for when we JSON something 35

The JsonSerializable Interface From the manual: JsonSerializable { abstract public mixed jsonserialize () } Objects implementing the JsonSerializable interface can control how they are represented in JSON when they are passed to json_encode() 36

JsonSerializable Example class gardenobject implements JsonSerializable { public function jsonserialize() { unset($this->herbs); return $this; } } $garden = new gardenobject(); $garden->flowers = array("clematis", "geranium", "hydrangea"); $garden->herbs = array("mint", "sage", "chives", "rosemary"); $garden->fruit = array("apple", "rhubarb"); echo json_encode($garden); {"flowers":["clematis","geranium","hydrangea"],"fruit" :["apple","rhubarb"]} 37

PHP 5.4

Did I Mention it s Faster? 39

The PHP 5.4 Features I ll Actually Use Short array syntax Traits Built in webserver Upload progress Callable JsonSerializable 40

Questions?

Resources All in a single bundle for you: http://lrnja.net/koouxv 42

Thanks! @lornajane http://lornajane.net 43