SlideShare ist ein Scribd-Unternehmen logo
1 von 13
PHP 5.4
New Language Features You Will Find
             Useful

          Sponsored by:
PHP 5.4
• UTF8 multibyte support now enabled by default in install
• session_status(), Binary syntax, number_format(), hex2bin()
• Classes
   –   invocation without constructor
   –   Class::{expr}() support for static methods
   –   Class constructor chaining
   –   Indirect method call using array
• Arrays
   – Short syntax
   – Dereferencing of functions
• mysqli results traversable
• Traits
• Some JSON stuff and more…
Session_status()
• Returns current session status
• 2 if session is active
• Else 1
Some number stuff
• Binary notation
       $bin = 0b0111010;
       print_r($b);
• number_format now allows multibyte thousands seperator
  and decimal char - it used to truncate to first char for both
       echo number_format(123456789.654321, 6, '߀', '©Ü');
       => 123©Ü456©Ü789߀654321
• hex2bin() now provided (bin2hex already existed)
       $hex = bin2hex(“iauerv");
       $bin = hex2bin($hex);
Class invocation without construction
• ReflectionClass::newInstanceWithoutConstructor
• Creates a new class instance without invoking the constructor.

   class ClassConstruct1{
       public function __construct(){
         echo "Class #1 constructor";
       }
       public function whatisit(){
         echo 'It is Class #1';
      }
   }
   $cc2 = new ReflectionClass("ClassConstruct1");
   $func = $cc2->newInstanceWithoutConstructor();
   $func->whatisit();
Class::{expr}()
• Static calls by string or variable previously unsupported
  class ClassConstruct1{
     public function __construct(){
        echo "Class #1 constructor";
     }
     public static function 'staticwhatisit(){
        echo 'It is Class #1';
    }
  }
  $func = 'staticwhatisit';
  $test = new ClassConstruct1();
  echo "<br>";
  $test::$func();
Constructor chaining
• (new ClassConstruct1)->whatisit();
• NOTE: the type hints and the number of
  required arguments must be the same now for
  constructors of abstract classes and their
  extensions – previously NOT the case. In 5.3 a
  different type hint would not fail. In 5.4 it will
  throw a catchable error.
Indirect method call using array
• call a function from an array using class name
  and function name as parameters
  class ClassConstruct{
       public function __construct(){
       }
       public static function dosomething($animal){
                echo "I am a classy $animal.";
       }
  }
  $func = array('ClassConstruct', 'dosomething');
  $func(“cow”);
Array dereferencing of functions
• Dereference the returned array without assigning to a var!!!
class FooBar
{
          protected $foobar_array = array();
          public function __construct()
          {
                    // NOTE THE JAVA-ESQUE SHORT SYNTAX BELOW
                    $this->foobar_array = [0 => 'foo',1 => 'bar'];
          }
          public function returnArray()
          {
                    return $this->foobar_array;
          }
}
$ac = new FooBar();
echo $ac->returnArray()[0] . $ac->returnArray()[1];
JSON
• Some new JSON formats for json_encode()
     •   JSON_UNESCAPED_UNICODE
     •   JSON_BIGINT_AS_STRING
     •   JSON_NUMERIC_CHECK
     •   JSON_PRETTY_PRINT
     •    JSON_UNESCAPED_SLASHES
Traits
• Provides functionality to be inherited but not
  instantiated.
• Groups functionality that is related by
  methodology, but not type.
• Implemented by the use keyword.
• Provides means for conflict resolution using
  the insteadof keyword
• Child f() > trait f() > parent/abstract f()
Other…
• mysqli results traceble
• JsonSerializable::jsonSerialize mixed class
• SCANDIR_SORT_NONE added for scandir to skip sorting – faster?
   Dunno.
• Some new CURL extensions (limit your server BW consumption)
    CURLOPT_MAX_RECV_SPEED_LARGE
    CURLOPT_MAX_SEND_SPEED_LARGE
 • Some new Iterator functionality
   –   RegexIterator::getRegex() returns the regex
   –   CallbackFilterIterator can take an iterator (with a set of data) and apply a
       filter function to it as it iterates.
$closure =function($final_slide){printf($final_slide)}

Sponsor (venue & pizza)
      Tipping Canoe
Speaker
      David Engel
      davidengel.dev@gmail.com
Binaries & Tars
      http://qa.php.net/
      http://windows.php.net/qa/
Next RC should be out this week.

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Nilesh Jayanandana
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)Jacek Laskowski
 
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...John De Goes
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeCory Forsyth
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applicationsSkills Matter
 
Optimizing Tcl Bytecode
Optimizing Tcl BytecodeOptimizing Tcl Bytecode
Optimizing Tcl BytecodeDonal Fellows
 
Making an Object System with Tcl 8.5
Making an Object System with Tcl 8.5Making an Object System with Tcl 8.5
Making an Object System with Tcl 8.5Donal Fellows
 
The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.5.1 book - Part 74 of 180The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.5.1 book - Part 74 of 180Mahmoud Samir Fayed
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分bob_is_strange
 
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014Susan Potter
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.boyney123
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraDeependra Ariyadewa
 
T3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerT3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerDavid Muñoz Díaz
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6FITC
 
Database API, your new friend
Database API, your new friendDatabase API, your new friend
Database API, your new friendkikoalonsob
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)David de Boer
 

Was ist angesagt? (20)

EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
 
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to Come
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Optimizing Tcl Bytecode
Optimizing Tcl BytecodeOptimizing Tcl Bytecode
Optimizing Tcl Bytecode
 
Making an Object System with Tcl 8.5
Making an Object System with Tcl 8.5Making an Object System with Tcl 8.5
Making an Object System with Tcl 8.5
 
The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.5.1 book - Part 74 of 180The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.5.1 book - Part 74 of 180
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分
 
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
 
T3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerT3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmer
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
Database API, your new friend
Database API, your new friendDatabase API, your new friend
Database API, your new friend
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
 

Andere mochten auch

Andere mochten auch (6)

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
 
Cache is King!
Cache is King!Cache is King!
Cache is King!
 
Harder, Better, Faster, Stronger
Harder, Better, Faster, StrongerHarder, Better, Faster, Stronger
Harder, Better, Faster, Stronger
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
Last Month in PHP - December 2015
Last Month in PHP - December 2015Last Month in PHP - December 2015
Last Month in PHP - December 2015
 
Composer
ComposerComposer
Composer
 

Ähnlich wie PHP 5.4 New Language Features You Will Find Useful

Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3Nate Abele
 
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)Damien Seguy
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Mario Camou Riveroll
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3Toni Kolev
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.pptKhizar40
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
DIG1108C Lesson 6 - Fall 2014
DIG1108C Lesson 6 - Fall 2014DIG1108C Lesson 6 - Fall 2014
DIG1108C Lesson 6 - Fall 2014David Wolfpaw
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 
Damien seguy php 5.6
Damien seguy php 5.6Damien seguy php 5.6
Damien seguy php 5.6Damien Seguy
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentMark Niebergall
 
Come on, PHP 5.4!
Come on, PHP 5.4!Come on, PHP 5.4!
Come on, PHP 5.4!paulgao
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015Charles Nutter
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lispelliando dias
 

Ähnlich wie PHP 5.4 New Language Features You Will Find Useful (20)

Introduction to php oop
Introduction to php oopIntroduction to php oop
Introduction to php oop
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3
 
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)
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
DIG1108C Lesson 6 - Fall 2014
DIG1108C Lesson 6 - Fall 2014DIG1108C Lesson 6 - Fall 2014
DIG1108C Lesson 6 - Fall 2014
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Damien seguy php 5.6
Damien seguy php 5.6Damien seguy php 5.6
Damien seguy php 5.6
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to Deployment
 
Come on, PHP 5.4!
Come on, PHP 5.4!Come on, PHP 5.4!
Come on, PHP 5.4!
 
Dart
DartDart
Dart
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
 

PHP 5.4 New Language Features You Will Find Useful

  • 1. PHP 5.4 New Language Features You Will Find Useful Sponsored by:
  • 2. PHP 5.4 • UTF8 multibyte support now enabled by default in install • session_status(), Binary syntax, number_format(), hex2bin() • Classes – invocation without constructor – Class::{expr}() support for static methods – Class constructor chaining – Indirect method call using array • Arrays – Short syntax – Dereferencing of functions • mysqli results traversable • Traits • Some JSON stuff and more…
  • 3. Session_status() • Returns current session status • 2 if session is active • Else 1
  • 4. Some number stuff • Binary notation $bin = 0b0111010; print_r($b); • number_format now allows multibyte thousands seperator and decimal char - it used to truncate to first char for both echo number_format(123456789.654321, 6, '߀', '©Ü'); => 123©Ü456©Ü789߀654321 • hex2bin() now provided (bin2hex already existed) $hex = bin2hex(“iauerv"); $bin = hex2bin($hex);
  • 5. Class invocation without construction • ReflectionClass::newInstanceWithoutConstructor • Creates a new class instance without invoking the constructor. class ClassConstruct1{ public function __construct(){ echo "Class #1 constructor"; } public function whatisit(){ echo 'It is Class #1'; } } $cc2 = new ReflectionClass("ClassConstruct1"); $func = $cc2->newInstanceWithoutConstructor(); $func->whatisit();
  • 6. Class::{expr}() • Static calls by string or variable previously unsupported class ClassConstruct1{ public function __construct(){ echo "Class #1 constructor"; } public static function 'staticwhatisit(){ echo 'It is Class #1'; } } $func = 'staticwhatisit'; $test = new ClassConstruct1(); echo "<br>"; $test::$func();
  • 7. Constructor chaining • (new ClassConstruct1)->whatisit(); • NOTE: the type hints and the number of required arguments must be the same now for constructors of abstract classes and their extensions – previously NOT the case. In 5.3 a different type hint would not fail. In 5.4 it will throw a catchable error.
  • 8. Indirect method call using array • call a function from an array using class name and function name as parameters class ClassConstruct{ public function __construct(){ } public static function dosomething($animal){ echo "I am a classy $animal."; } } $func = array('ClassConstruct', 'dosomething'); $func(“cow”);
  • 9. Array dereferencing of functions • Dereference the returned array without assigning to a var!!! class FooBar { protected $foobar_array = array(); public function __construct() { // NOTE THE JAVA-ESQUE SHORT SYNTAX BELOW $this->foobar_array = [0 => 'foo',1 => 'bar']; } public function returnArray() { return $this->foobar_array; } } $ac = new FooBar(); echo $ac->returnArray()[0] . $ac->returnArray()[1];
  • 10. JSON • Some new JSON formats for json_encode() • JSON_UNESCAPED_UNICODE • JSON_BIGINT_AS_STRING • JSON_NUMERIC_CHECK • JSON_PRETTY_PRINT • JSON_UNESCAPED_SLASHES
  • 11. Traits • Provides functionality to be inherited but not instantiated. • Groups functionality that is related by methodology, but not type. • Implemented by the use keyword. • Provides means for conflict resolution using the insteadof keyword • Child f() > trait f() > parent/abstract f()
  • 12. Other… • mysqli results traceble • JsonSerializable::jsonSerialize mixed class • SCANDIR_SORT_NONE added for scandir to skip sorting – faster? Dunno. • Some new CURL extensions (limit your server BW consumption) CURLOPT_MAX_RECV_SPEED_LARGE CURLOPT_MAX_SEND_SPEED_LARGE • Some new Iterator functionality – RegexIterator::getRegex() returns the regex – CallbackFilterIterator can take an iterator (with a set of data) and apply a filter function to it as it iterates.
  • 13. $closure =function($final_slide){printf($final_slide)} Sponsor (venue & pizza) Tipping Canoe Speaker David Engel davidengel.dev@gmail.com Binaries & Tars http://qa.php.net/ http://windows.php.net/qa/ Next RC should be out this week.