PHP 5.4New 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(), hex2b...
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 thousand...
Class invocation without construction• ReflectionClass::newInstanceWithoutConstructor• Creates a new class instance withou...
Class::{expr}()• Static calls by string or variable previously unsupported  class ClassConstruct1{     public function __c...
Constructor chaining• (new ClassConstruct1)->whatisit();• NOTE: the type hints and the number of  required arguments must ...
Indirect method call using array• call a function from an array using class name  and function name as parameters  class C...
Array dereferencing of functions• Dereference the returned array without assigning to a var!!!class FooBar{          prote...
JSON• Some new JSON formats for json_encode()     •   JSON_UNESCAPED_UNICODE     •   JSON_BIGINT_AS_STRING     •   JSON_NU...
Traits• Provides functionality to be inherited but not  instantiated.• Groups functionality that is related by  methodolog...
Other…• mysqli results traceble• JsonSerializable::jsonSerialize mixed class• SCANDIR_SORT_NONE added for scandir to skip ...
$closure =function($final_slide){printf($final_slide)}Sponsor (venue & pizza)      Tipping CanoeSpeaker      David Engel  ...
Upcoming SlideShare
Loading in...5
×

Php 5.4: New Language Features You Will Find Useful

1,213

Published on

This is a presentation I gave on new language features in PHP 5.4 for the Winnipeg PHP user group on January 30, 2012.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,213
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Php 5.4: New Language Features You Will Find Useful

  1. 1. PHP 5.4New Language Features You Will Find Useful Sponsored by:
  2. 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. 3. Session_status()• Returns current session status• 2 if session is active• Else 1
  4. 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. 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. 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. 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. 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. 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. 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. 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. 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. 13. $closure =function($final_slide){printf($final_slide)}Sponsor (venue & pizza) Tipping CanoeSpeaker David Engel davidengel.dev@gmail.comBinaries & Tars http://qa.php.net/ http://windows.php.net/qa/Next RC should be out this week.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×