SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Downloaden Sie, um offline zu lesen
New Features
in PHP 5.3
Bradley Holt (http://bradley-holt.com/)
Introduction
Are you using PHP 5.3?
Past, Present & Future
PHP 5.0 brought us a new object model
PHP 5.3 brings us namespaces, closures,
late static binding & more
PHP 5.3.99—huh?
So What?
Speed & memory improvements
Some problems are easier to solve in PHP 5.3
Zend Framework 2.0, Symfony 2.0,
Lithium & Doctrine 2.0 will require PHP 5.3
New Features
Namespaces, Late Static
Binding & Closures
Namespaces
Namespaced Classes
<?php
namespace btvphpstuff;
class Foo {}
$a = new btvphpstuffFoo();
$b = new Foo(); // Same as above
Namespaced Functions
<?php
namespace btvphpstuff;
function sayHi()
{
return'Hi';
}
echo btvphpstuffsayHi(); // Hi
echo sayHi(); // Hi
Namespace Aliasing
Examples courtesy of Matthew Weier O’Phinney
(http://weierophinney.net/matthew/)
Aliasing Classes
<?php
namespace ZendSignalSlot {
class Signals {}
}
namespace { // global namespace
use ZendSignalSlotSignals;
$signals = new Signals();
}
Changing the Name
<?php
namespace ZendLoader {
class PluginBroker {}
}
namespace {
use ZendLoaderPluginBroker as Broker;
$broker = new Broker();
}
Global Resolution
<?php
namespace Doctrine {
class Manager {
public static function load() {}
}
}
namespace {
DoctrineManager::load();
}
Late Static Binding
The Problem
Parent Class
<?php
class Foo {
protected static function speak() {
return 'Hi';
}
public static function sayHi() {
return self::speak();
}
}
Child Class
<?php
class Bar extends Foo {
protected static function speak() {
return 'Hello';
}
}
“Hi”or“Hello”?
<?php
echo Bar::sayHi();
“Hi”or“Hello”?
<?php
echo Bar::sayHi(); // Hi
The Solution
Parent Class
<?php
class Foo {
protected static function speak() {
return 'Hi';
}
public static function sayHi() {
return static::speak();
}
}
Child Class
<?php
class Bar extends Foo {
protected static function speak() {
return 'Hello';
}
}
“Hi”or“Hello”?
<?php
echo Bar::sayHi(); // Hello
Closures / Lambda Functions
See: http://bit.ly/9LYP3r
Variable Assignment
<?php
$sayHi = function () {
return 'Hi';
};
echo $sayHi(); // Hi
Scope
<?php
$sayWhat = 'Hi';
$say = function ($toWhom) use ($sayWhat) {
return $sayWhat . ', ' . $toWhom;
};
echo $say('Bradley'); // Hi, Bradley
Anonymous Functions
<?php
$values = array(3, 7, 2);
usort($values, function ($a, $b) {
if ($a == $b) { return 0; }
return ($a < $b) ? -1 : 1;
});
/* [0] => 2
[1] => 3
[2] => 7 */
Other Neat Stuff
New Bundled Extensions
Phar (PHP Archive)
Internationalization Functions
Fileinfo: guesses content type & encoding
SQLite version 3
Enchant spelling library
Extension Improvements
OpenSSL
More OpenSSL functionality
available natively within PHP
Faster than do-it-yourself or system calls
Useful if you’re working with OpenID, etc.
DateTime Object
Add or subtract date intervals
Calculate the difference between two dates
Get or set unix timestamp
See: http://bit.ly/5pDpWI
SPL Data Structures
See: http://bit.ly/bz6pqY
SplStack
Push & Pop
Last In, First Out (LIFO)
Uses less memory than arrays for big stacks
(greater than 5,000 elements)
SplQueue
Enqueue & Dequeue
First In, First Out (FIFO)
Faster and uses less memory
than arrays for most queues
SplHeap
Insert & Remove
Reorders elements based
on comparisons
Faster and uses less memory
than arrays for most heaps
goto
Courtesy of xkcd:
http://xkcd.com/292/
New Syntax
__invoke()
<?php
class Foo {
public function __invoke($x) {
return $x + $x;
}
}
$foo = new Foo();
echo $foo(2); // 4
__callStatic()
<?php
class Foo {
public static function __callStatic
($name, $args) {
return $name . ' called
statically';
}
}
echo Foo::bar(); // bar called statically
__DIR__
<?php
echo dirname(__FILE__);
echo __DIR__; // Since PHP 5.3
Miscellaneous
Nowdocs:“Nowdocs are to single-quoted strings what heredocs
are to double-quoted strings.”
Improved ternary (?:) operator
I’m Sold, What Now?
Platform Support
Linux
Ubuntu 10.10
Fedora 12+
openSuse 11.2+
Red Hat Enterprise Linux (RHEL) 6
Mac OS X
Bundled with Snow Leopard
MacPorts
Homebrew
Windows
Binary packages available
WebMatrix Beta 3
PHP 5.3 Hosting
ServerGrove
WebMatrix
A2 Hosting
Hostek
Resources
PHP Manual
http://php.net/
PHP 5.3.0 Release Announcement
http://php.net/releases/5_3_0.php
Migrating from PHP 5.2.x to PHP 5.3.x
http://www.php.net/manual/en/migration53.php
Questions?
Thank You
Bradley Holt (http://bradley-holt.com/)
New Features in PHP 5.3 by Bradley Holt is licensed under a
Creative Commons Attribution 3.0 Unported License.
License

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
 
Sa
SaSa
Sa
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Session Server - Maintaing State between several Servers
Session Server - Maintaing State between several ServersSession Server - Maintaing State between several Servers
Session Server - Maintaing State between several Servers
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
Using PHP
Using PHPUsing PHP
Using PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6
 
PHP Function
PHP Function PHP Function
PHP Function
 
Writing and using php streams and sockets
Writing and using php streams and socketsWriting and using php streams and sockets
Writing and using php streams and sockets
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flask
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3
 
Web Development Course: PHP lecture 4
Web Development Course: PHP  lecture 4Web Development Course: PHP  lecture 4
Web Development Course: PHP lecture 4
 

Andere mochten auch

Mantra of marketing,mix,customer values
Mantra of marketing,mix,customer valuesMantra of marketing,mix,customer values
Mantra of marketing,mix,customer values
Ajay Samyal
 
Chapter 10 Synchronous Communication
Chapter 10 Synchronous CommunicationChapter 10 Synchronous Communication
Chapter 10 Synchronous Communication
Patty Ramsey
 
300 Years of Groundwater Management, Charles Porter
300 Years of Groundwater Management, Charles Porter300 Years of Groundwater Management, Charles Porter
300 Years of Groundwater Management, Charles Porter
TXGroundwaterSummit
 
Chapter 4 Form Factors & Power Supplies
Chapter 4 Form Factors & Power SuppliesChapter 4 Form Factors & Power Supplies
Chapter 4 Form Factors & Power Supplies
Patty Ramsey
 
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water ResourcesWE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
grssieee
 

Andere mochten auch (20)

PHP 5.6 New and Deprecated Features
PHP 5.6  New and Deprecated FeaturesPHP 5.6  New and Deprecated Features
PHP 5.6 New and Deprecated Features
 
WordPress as a CMS v2
WordPress as a CMS v2WordPress as a CMS v2
WordPress as a CMS v2
 
Gluecon 2013 - Dark Architecture and How to Forklift Upgrade Your System - Dy...
Gluecon 2013 - Dark Architecture and How to Forklift Upgrade Your System - Dy...Gluecon 2013 - Dark Architecture and How to Forklift Upgrade Your System - Dy...
Gluecon 2013 - Dark Architecture and How to Forklift Upgrade Your System - Dy...
 
Mantra of marketing,mix,customer values
Mantra of marketing,mix,customer valuesMantra of marketing,mix,customer values
Mantra of marketing,mix,customer values
 
Caracas en los años 40
Caracas en los años 40Caracas en los años 40
Caracas en los años 40
 
Урок 55. Практична робота 15. Використання математичних, логічних та статисти...
Урок 55. Практична робота 15. Використання математичних, логічних та статисти...Урок 55. Практична робота 15. Використання математичних, логічних та статисти...
Урок 55. Практична робота 15. Використання математичних, логічних та статисти...
 
25 php interview questions – codementor
25 php interview questions – codementor25 php interview questions – codementor
25 php interview questions – codementor
 
Guidelines for Modelling Groundwater Surface Water Interaction in eWater Source
Guidelines for Modelling Groundwater Surface Water Interaction in eWater SourceGuidelines for Modelling Groundwater Surface Water Interaction in eWater Source
Guidelines for Modelling Groundwater Surface Water Interaction in eWater Source
 
PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
 
Chapter 10 Synchronous Communication
Chapter 10 Synchronous CommunicationChapter 10 Synchronous Communication
Chapter 10 Synchronous Communication
 
Final morris esri_nwgis_lidar
Final morris esri_nwgis_lidarFinal morris esri_nwgis_lidar
Final morris esri_nwgis_lidar
 
Chapter 5 Input
Chapter 5 InputChapter 5 Input
Chapter 5 Input
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
300 Years of Groundwater Management, Charles Porter
300 Years of Groundwater Management, Charles Porter300 Years of Groundwater Management, Charles Porter
300 Years of Groundwater Management, Charles Porter
 
Chapter 4 Form Factors & Power Supplies
Chapter 4 Form Factors & Power SuppliesChapter 4 Form Factors & Power Supplies
Chapter 4 Form Factors & Power Supplies
 
Emoji International Name Finder
Emoji International Name FinderEmoji International Name Finder
Emoji International Name Finder
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability ExtensionPreparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water ResourcesWE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
 

Ähnlich wie New Features in PHP 5.3

Tips
TipsTips
Tips
mclee
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 

Ähnlich wie New Features in PHP 5.3 (20)

ZendCon 08 php 5.3
ZendCon 08 php 5.3ZendCon 08 php 5.3
ZendCon 08 php 5.3
 
10 Lines or Less; Interesting Things You Can Do In Java With Minimal Code
10 Lines or Less; Interesting Things You Can Do In Java With Minimal Code10 Lines or Less; Interesting Things You Can Do In Java With Minimal Code
10 Lines or Less; Interesting Things You Can Do In Java With Minimal Code
 
BP107: Ten Lines Or Less: Interesting Things You Can Do In Java With Minimal ...
BP107: Ten Lines Or Less: Interesting Things You Can Do In Java With Minimal ...BP107: Ten Lines Or Less: Interesting Things You Can Do In Java With Minimal ...
BP107: Ten Lines Or Less: Interesting Things You Can Do In Java With Minimal ...
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Tips
TipsTips
Tips
 
PHP 5.3
PHP 5.3PHP 5.3
PHP 5.3
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Php 7 compliance workshop singapore
Php 7 compliance workshop singaporePhp 7 compliance workshop singapore
Php 7 compliance workshop singapore
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
PHP File Handling
PHP File Handling PHP File Handling
PHP File Handling
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
PHP 7 - A look at the future
PHP 7 - A look at the futurePHP 7 - A look at the future
PHP 7 - A look at the future
 
PHP7 - A look at the future
PHP7 - A look at the futurePHP7 - A look at the future
PHP7 - A look at the future
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Static analysis saved my code tonight
Static analysis saved my code tonightStatic analysis saved my code tonight
Static analysis saved my code tonight
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 

Mehr von Bradley Holt

Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012
Bradley Holt
 

Mehr von Bradley Holt (14)

Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012
 
Domain-Driven Design
Domain-Driven DesignDomain-Driven Design
Domain-Driven Design
 
Entity Relationships in a Document Database at CouchConf Boston
Entity Relationships in a Document Database at CouchConf BostonEntity Relationships in a Document Database at CouchConf Boston
Entity Relationships in a Document Database at CouchConf Boston
 
CouchConf NYC CouchApps
CouchConf NYC CouchAppsCouchConf NYC CouchApps
CouchConf NYC CouchApps
 
ZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven Design
 
ZendCon 2011 Learning CouchDB
ZendCon 2011 Learning CouchDBZendCon 2011 Learning CouchDB
ZendCon 2011 Learning CouchDB
 
jQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsjQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchApps
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
OSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBOSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDB
 
Load Balancing with Apache
Load Balancing with ApacheLoad Balancing with Apache
Load Balancing with Apache
 
CouchDB at New York PHP
CouchDB at New York PHPCouchDB at New York PHP
CouchDB at New York PHP
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
Zend Framework Quick Start Walkthrough
Zend Framework Quick Start WalkthroughZend Framework Quick Start Walkthrough
Zend Framework Quick Start Walkthrough
 
Burlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion PresentationBurlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion Presentation
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

New Features in PHP 5.3