SlideShare una empresa de Scribd logo
1 de 29
Announcements PHP 5.2.10 is available (June 18 release) CodeWorks 2009 Announced – Washington, D.C. Tutorial Day: October 2 Main Conference: October 3 Two day conference for PHP developers Each event is limited to 300 attendees http://cw.mtacon.com/signup/index to Register Discount prices until July 15 2009 DC PHP Conference & Expo September 16 & 17 Discount prices until August 15 No sessions available yet 1
PHP 5.3 July 2009 Baltimore/Washington PHP Meetup Chris Stone chris@emoxie.com Follow me @cmstone
Release Information Existing code should still work There are only a few incompatibilities and new features that should be considered Major improvement of the 5.x series Over 140 bug fixes Comprehensive migration information from PHP 5.2.x to 5.3.x at: http://us.php.net/migration53 3
Key Features Namespace support Late static binding Lambda functions/closures (anonymous) Syntax additions (NOWDOC, ?:, goto…) Performance improvements Garbage collection for cyclic references mysqlnd PHP native replacement for libmysql Deprecation notices are handled E_DEPRECATED instead of E_STRICT 4
Improved Performance Improved runtime speed Improved memory usage Smaller binary size Faster startup speed with GCC4 md5() is faster (10-15%) require_once() and include_once() uses only 1  fopen(3) call Improved exception handling Overall performance improvement of 5-15% 5
Namespaces
Namespaces Single largest addition in 5.3 Feature complete Simplifies naming conventions If you developed larger projects, you would probably have used long class names i.e. Zend class names can be HUGE Zend_Search_Lucene_Document_Html Different namespaces can contain classes, functions, and constants with the same name. Defined using the namespace keyword 7
Sub Namespaces <?phpnamespace Project1ubevel;const CONNECT_OK = 1;class Connection { /* ... */ }function connect() { /* ... */  } ?>  8
Multiple Namespaces Per File <?phpnamespace Project 1;const CONNECT_OK = 1;class Connection { /* ... */ }function connect() { /* ... */  } namespace Project2;const CONNECT_OK = 1;class Connection { /* ... */ }function connect() { /* ... */  } ?>  9
Namespaces Aliasing/Importing PHP namespaces support two kinds of aliasing or importing: aliasing a class name, and aliasing a namespace name. <?phpnamespace foo;use Myulllassname as Another;// this is the same as use MyullSname as NSnameuse MyullSname;// importing a global classuse rrayObject;$obj = new namespacenother; // instantiates object of class foonother $obj = new Another; // instantiates object of class MyulllassnameNSnameubnsunc(); // calls function MyullSnameubnsunc$a = new ArrayObject(array(1)); // instantiates object of class ArrayObject// without the "use rrayObject" we would instantiate an object of class foorrayObject ?>  10
Namespaces Aliasing/Importing PHP additionally supports a convenience shortcut to place multiple use statements on the same line  <?phpuse Myulllassname as Another, MyullSname;$obj = new Another; // instantiates object of class Myulllassname NSnameubnsunc();  // calls function MyullSnameubnsunc ?>  11
Namespaces Aliasing/Importing PHP additionally supports a convenience shortcut to place multiple use statements on the same line  <?phpuse Myulllassname as Another, MyullSname;$obj = new Another; // instantiates object of class Myulllassname NSnameubnsunc();  // calls function MyullSnameubnsunc ?>  12
Common Namespace Questions Q:	If I don't use namespaces, should I care 	about any of this? A:	No. Namespaces do not affect any existing 	code in any way, or any as-yet-to-be-	written code that does not contain 	namespaces. Q:	How does a name like yame or ame 	resolve?  A:		Names that begin with a always resolve to 	what they look like, so yame is in fact 	myame, and xception is Exception. 13
MySQLnd – MySQL Native Driver Replacement for the MySQL Client Library Does NOT provide a new API to the programmer High speed library to interface with MySQL designed for PHP Built in driver No external dependencies Improved persistent connections The special function mysqli_fetch_all() Return all rows as an array with one function Can fetch performance statistics mysqli_get_cache_stats() mysqli_get_client_stats() mysqli_get_connection_stats() 14
New Language Features
__DIR__ __DIR__ is a magic constant that indicates where the current script is located. The below produce the same thing: <?php /* PHP < 5.3 */ 	echo dirname(__FILE__); /* PHP >= 5.3 */ echo __DIR__; ?> 16
?: Ternary Operator It’s now possible to leave out the middle part of the ternary operator.  This allows fast retrieval of a non-empty value from 2 values and/or expressions. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise.  <?php $test = true ?: false; // Returns true $test = false ?: true; // Returns true $test = 0 ?: 2; // Returns 2 $test = “” ?: 1; // Returns 1 ?> 17
__callStatic Same as __call, except for static methods Example <?php class tester { 	static function __callStatic($name, $args) { 		echo $name . ‘ (‘ . implode(‘,’, $args) . ‘)’; 	} } tester::testFunction(“test1”, “test2”); ?> Outputs testFunction(test1,test2); Note:  Dynamic function calls (static/standard) are slow 18
Dynamic Static Calls PHP 5.3 introduced the ability to call static method dynamically <?php class tester { 	static functionfoobar() { 		echo “Dynamic Static Call”; 	} } $variable1 = “tester”; $variable2 = “foobar”; $variable1::$variable2();   // Calls tester:foobar(); ?> Outputs Dynamic Static Call Note:  Dynamic function calls (static/standard) are slow 19
Late Static Binding Limitations of self:: <?phpclass A {    public static function who() {        echo __CLASS__;    }    public static function test() {        self::who();    }}class B extends A {    public static function who() {         echo __CLASS__;    }}B::test();?> Output A 20 Late static binding is used to reference the called class in a context of static inheritance.  Processing of static events has been moved from compile time, to execution time. static:: simple usage <?phpclass A {    public static function who() {        echo __CLASS__;    }    public static function test() {        static::who();    }}class B extends A {    public static function who() {         echo __CLASS__;    }} B::test(); ?> Output B
Anonymous Functions Also known as closures, allow the creation of functions which have no specified name.  They are most useful as the value of a callback parameter. Example #1 - Anonymous function example <?phpecho preg_replace_callback('~-([a-z])~', function ($match) {    return strtoupper($match[1]);}, 'hello-world');?>  Outputs helloWorld Example #2 - Anonymous function variable assignment example <?php$greet = function($name) {    printf("Hello %s", $name);};$greet('World');$greet('PHP');?>  Outputs Hello World Hello PHP 21
goto The goto operator can be used to jump to another section in the program. The target point is specified by a label followed by a colon, and the instruction is given as goto followed by the desired target label. This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. You may jump out of these, and a common use is to use a goto in place of a multi-level break.  Example #1 – goto Example <?phpgoto a;echo 'Foo'; a:echo 'Bar';?>  Outputs Bar 22
goto Continued… Example #2 - Anonymous function variable assignment example <?phpfor ($i=0,$j=50; $i<100; $i++) {  while ($j--) {    if ($j==17) goto end;   }}echo "i = $i";end:echo 'j hit 17';?>  Outputs j hit 17 23
Deprecation New error modes  E_USER_DEPRECATED E_DEPRECATED Used to inform about deprecated functionality that is scheduled for removal in future version of PHP. Used to throw E_STRICT 24
INI File Handling
INI Changes Overview Support for .htaccess style INI controls Per directory/host INI settings that can not be overridden by the user [PATH=/var/www/www.phpmeetup.com/] [HOST=www.meetup.com] Only supported by CGI/FastCGI, not for PHP-CLI, or as an Apache module Improved error handling "ini-variables" can now be used almost anywhere in a php.ini file. 26
INI Changes Example Name for user-defined php.ini (.htaccess) files. Default is ".user.ini“ user_ini.filename= ".user.ini" To disable this feature set this option to empty value user_ini.filename= TTL for user-defined php.ini files (time-to-live) in seconds. Default is 300 seconds (5 minutes) user_ini.cache_ttl= 300 [PATH=/var/www/phpmeetup.com] error_reporting= E_ALL & ~E_DEPRECATED html_errors = off 27
Other Improvements Improved streams Improved DNS API Improved hash extension Improved IMAP support Improved mbstring extension Improved OCI8 extension Improved OpenSSL (OpenID in mind, simplify implementation) Improved crypt() function Many, many more! 28
The End Slides will be posted on MeetUp and http://www.e-moxie.com I can also e-mail them to you if you would like, just make sure I have your e-mail address. Next Topic Project & Code Management using Trac w/ 	Subversion Integration Presented by Steve Crump August 12, 2009 @ 6:30 p.m. 29

Más contenido relacionado

La actualidad más candente

Php tutorial
Php tutorialPhp tutorial
Php tutorial
Niit
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
olracoatalub
 

La actualidad más candente (20)

The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationPHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail Explanation
 
Perl Tidy Perl Critic
Perl Tidy Perl CriticPerl Tidy Perl Critic
Perl Tidy Perl Critic
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?
 
CLI, the other SAPI
CLI, the other SAPICLI, the other SAPI
CLI, the other SAPI
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Insecure coding in C (and C++)
Insecure coding in C (and C++)Insecure coding in C (and C++)
Insecure coding in C (and C++)
 
PHP 7
PHP 7PHP 7
PHP 7
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016
 
Yapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlYapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line Perl
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
 
2 debugging-c
2 debugging-c2 debugging-c
2 debugging-c
 
Deep C
Deep CDeep C
Deep C
 
Boo Manifesto
Boo ManifestoBoo Manifesto
Boo Manifesto
 

Destacado

Destacado (6)

Brudnick Net Ppt Portfolio
Brudnick Net Ppt PortfolioBrudnick Net Ppt Portfolio
Brudnick Net Ppt Portfolio
 
Shell Revolution
Shell RevolutionShell Revolution
Shell Revolution
 
Charm City Linux - Jan 2014 - Web Dev Made Easy - Shell Revolution
Charm City Linux - Jan 2014 - Web Dev Made Easy - Shell RevolutionCharm City Linux - Jan 2014 - Web Dev Made Easy - Shell Revolution
Charm City Linux - Jan 2014 - Web Dev Made Easy - Shell Revolution
 
Lai
LaiLai
Lai
 
Cutting Edge Proposal
Cutting Edge ProposalCutting Edge Proposal
Cutting Edge Proposal
 
On Air
On AirOn Air
On Air
 

Similar a PHP 5.3

course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
jsmith92
 

Similar a PHP 5.3 (20)

course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
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
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
Php 7 compliance workshop singapore
Php 7 compliance workshop singaporePhp 7 compliance workshop singapore
Php 7 compliance workshop singapore
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)
 
Php
PhpPhp
Php
 
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
 
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
 
Php
PhpPhp
Php
 
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
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 
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
 
Exakat for PHP : smart code reviewing engine
Exakat for PHP : smart code reviewing engineExakat for PHP : smart code reviewing engine
Exakat for PHP : smart code reviewing engine
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

PHP 5.3

  • 1. Announcements PHP 5.2.10 is available (June 18 release) CodeWorks 2009 Announced – Washington, D.C. Tutorial Day: October 2 Main Conference: October 3 Two day conference for PHP developers Each event is limited to 300 attendees http://cw.mtacon.com/signup/index to Register Discount prices until July 15 2009 DC PHP Conference & Expo September 16 & 17 Discount prices until August 15 No sessions available yet 1
  • 2. PHP 5.3 July 2009 Baltimore/Washington PHP Meetup Chris Stone chris@emoxie.com Follow me @cmstone
  • 3. Release Information Existing code should still work There are only a few incompatibilities and new features that should be considered Major improvement of the 5.x series Over 140 bug fixes Comprehensive migration information from PHP 5.2.x to 5.3.x at: http://us.php.net/migration53 3
  • 4. Key Features Namespace support Late static binding Lambda functions/closures (anonymous) Syntax additions (NOWDOC, ?:, goto…) Performance improvements Garbage collection for cyclic references mysqlnd PHP native replacement for libmysql Deprecation notices are handled E_DEPRECATED instead of E_STRICT 4
  • 5. Improved Performance Improved runtime speed Improved memory usage Smaller binary size Faster startup speed with GCC4 md5() is faster (10-15%) require_once() and include_once() uses only 1 fopen(3) call Improved exception handling Overall performance improvement of 5-15% 5
  • 7. Namespaces Single largest addition in 5.3 Feature complete Simplifies naming conventions If you developed larger projects, you would probably have used long class names i.e. Zend class names can be HUGE Zend_Search_Lucene_Document_Html Different namespaces can contain classes, functions, and constants with the same name. Defined using the namespace keyword 7
  • 9. Multiple Namespaces Per File <?phpnamespace Project 1;const CONNECT_OK = 1;class Connection { /* ... */ }function connect() { /* ... */  } namespace Project2;const CONNECT_OK = 1;class Connection { /* ... */ }function connect() { /* ... */  } ?> 9
  • 10. Namespaces Aliasing/Importing PHP namespaces support two kinds of aliasing or importing: aliasing a class name, and aliasing a namespace name. <?phpnamespace foo;use Myulllassname as Another;// this is the same as use MyullSname as NSnameuse MyullSname;// importing a global classuse rrayObject;$obj = new namespacenother; // instantiates object of class foonother $obj = new Another; // instantiates object of class MyulllassnameNSnameubnsunc(); // calls function MyullSnameubnsunc$a = new ArrayObject(array(1)); // instantiates object of class ArrayObject// without the "use rrayObject" we would instantiate an object of class foorrayObject ?> 10
  • 11. Namespaces Aliasing/Importing PHP additionally supports a convenience shortcut to place multiple use statements on the same line <?phpuse Myulllassname as Another, MyullSname;$obj = new Another; // instantiates object of class Myulllassname NSnameubnsunc();  // calls function MyullSnameubnsunc ?> 11
  • 12. Namespaces Aliasing/Importing PHP additionally supports a convenience shortcut to place multiple use statements on the same line <?phpuse Myulllassname as Another, MyullSname;$obj = new Another; // instantiates object of class Myulllassname NSnameubnsunc();  // calls function MyullSnameubnsunc ?> 12
  • 13. Common Namespace Questions Q: If I don't use namespaces, should I care about any of this? A: No. Namespaces do not affect any existing code in any way, or any as-yet-to-be- written code that does not contain namespaces. Q: How does a name like yame or ame resolve? A: Names that begin with a always resolve to what they look like, so yame is in fact myame, and xception is Exception. 13
  • 14. MySQLnd – MySQL Native Driver Replacement for the MySQL Client Library Does NOT provide a new API to the programmer High speed library to interface with MySQL designed for PHP Built in driver No external dependencies Improved persistent connections The special function mysqli_fetch_all() Return all rows as an array with one function Can fetch performance statistics mysqli_get_cache_stats() mysqli_get_client_stats() mysqli_get_connection_stats() 14
  • 16. __DIR__ __DIR__ is a magic constant that indicates where the current script is located. The below produce the same thing: <?php /* PHP < 5.3 */ echo dirname(__FILE__); /* PHP >= 5.3 */ echo __DIR__; ?> 16
  • 17. ?: Ternary Operator It’s now possible to leave out the middle part of the ternary operator. This allows fast retrieval of a non-empty value from 2 values and/or expressions. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise. <?php $test = true ?: false; // Returns true $test = false ?: true; // Returns true $test = 0 ?: 2; // Returns 2 $test = “” ?: 1; // Returns 1 ?> 17
  • 18. __callStatic Same as __call, except for static methods Example <?php class tester { static function __callStatic($name, $args) { echo $name . ‘ (‘ . implode(‘,’, $args) . ‘)’; } } tester::testFunction(“test1”, “test2”); ?> Outputs testFunction(test1,test2); Note: Dynamic function calls (static/standard) are slow 18
  • 19. Dynamic Static Calls PHP 5.3 introduced the ability to call static method dynamically <?php class tester { static functionfoobar() { echo “Dynamic Static Call”; } } $variable1 = “tester”; $variable2 = “foobar”; $variable1::$variable2(); // Calls tester:foobar(); ?> Outputs Dynamic Static Call Note: Dynamic function calls (static/standard) are slow 19
  • 20. Late Static Binding Limitations of self:: <?phpclass A {    public static function who() {        echo __CLASS__;    }    public static function test() {        self::who();    }}class B extends A {    public static function who() {         echo __CLASS__;    }}B::test();?> Output A 20 Late static binding is used to reference the called class in a context of static inheritance. Processing of static events has been moved from compile time, to execution time. static:: simple usage <?phpclass A {    public static function who() {        echo __CLASS__;    }    public static function test() {        static::who();    }}class B extends A {    public static function who() {         echo __CLASS__;    }} B::test(); ?> Output B
  • 21. Anonymous Functions Also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of a callback parameter. Example #1 - Anonymous function example <?phpecho preg_replace_callback('~-([a-z])~', function ($match) {    return strtoupper($match[1]);}, 'hello-world');?> Outputs helloWorld Example #2 - Anonymous function variable assignment example <?php$greet = function($name) {    printf("Hello %s", $name);};$greet('World');$greet('PHP');?> Outputs Hello World Hello PHP 21
  • 22. goto The goto operator can be used to jump to another section in the program. The target point is specified by a label followed by a colon, and the instruction is given as goto followed by the desired target label. This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one. You also cannot jump into any sort of loop or switch structure. You may jump out of these, and a common use is to use a goto in place of a multi-level break. Example #1 – goto Example <?phpgoto a;echo 'Foo'; a:echo 'Bar';?> Outputs Bar 22
  • 23. goto Continued… Example #2 - Anonymous function variable assignment example <?phpfor ($i=0,$j=50; $i<100; $i++) {  while ($j--) {    if ($j==17) goto end;   }}echo "i = $i";end:echo 'j hit 17';?> Outputs j hit 17 23
  • 24. Deprecation New error modes E_USER_DEPRECATED E_DEPRECATED Used to inform about deprecated functionality that is scheduled for removal in future version of PHP. Used to throw E_STRICT 24
  • 26. INI Changes Overview Support for .htaccess style INI controls Per directory/host INI settings that can not be overridden by the user [PATH=/var/www/www.phpmeetup.com/] [HOST=www.meetup.com] Only supported by CGI/FastCGI, not for PHP-CLI, or as an Apache module Improved error handling "ini-variables" can now be used almost anywhere in a php.ini file. 26
  • 27. INI Changes Example Name for user-defined php.ini (.htaccess) files. Default is ".user.ini“ user_ini.filename= ".user.ini" To disable this feature set this option to empty value user_ini.filename= TTL for user-defined php.ini files (time-to-live) in seconds. Default is 300 seconds (5 minutes) user_ini.cache_ttl= 300 [PATH=/var/www/phpmeetup.com] error_reporting= E_ALL & ~E_DEPRECATED html_errors = off 27
  • 28. Other Improvements Improved streams Improved DNS API Improved hash extension Improved IMAP support Improved mbstring extension Improved OCI8 extension Improved OpenSSL (OpenID in mind, simplify implementation) Improved crypt() function Many, many more! 28
  • 29. The End Slides will be posted on MeetUp and http://www.e-moxie.com I can also e-mail them to you if you would like, just make sure I have your e-mail address. Next Topic Project & Code Management using Trac w/ Subversion Integration Presented by Steve Crump August 12, 2009 @ 6:30 p.m. 29