What’s coming in PHP 5.3
By Stas Malyshev




                           Copyright © 2007, Zend Technologies Inc.
5.2 vs 5.3 vs 6


  • 5.3 is a major version, should be 5½.0

  • 6 taking long time, features drift back

  • No sudden m...
Syntax


  • Namespaces!
  •   Late static binding (static::foo vs self::foo)
  •   $classname::method()
  •   __callstati...
Functions


  •   Phar – PHP Archive
  •   Pect/intl – ICU support
  •   MySQLnd
  •   INI magic – per dir, per user, .hta...
Engine


  • Garbage collection!
  • Stack usage improvements
  • Opcode optimizations
  • System call reduction




     ...
Namespaces

 define(“MY_HTTP_GET”, 1);        namespace My::Http;
 define(“MY_HTTP_POST”, 2);
                            ...
Namespaces

 • Organize OO code into self-contained units
 • Reduce conflicts
 • Shorten names
      class
       Zend_Se...
Namespaces – new syntax


  • namespace foo::bar;
  • use foo::bar as baz, boo::hoo::foo;

  • __NAMESPACE__
  • namespace...
Late Static Binding

Gateway to ActiveRecord
class Singleton {
   const ID = 0;
   static $instance = array();
   static f...
Dynamic class name

 Everything can be variable, class name too
 class DbDriver {
    const NAME = “MySQLDriver”;
    stat...
__callStatic

 __call‟s static cousin
 class DummyDriver {
    const NAME = „Dummy‟;
    static function __callstatic($nam...
?:

 Shortcut for $a?$a:$b
 $name = $_GET[„name‟] ?: „anonymous‟;




                                         What's new ...
goto

 Guess what it does ;)
 RETRY:
 try {
    …
 } catch (Exception $e) {
    recovery($e);
    goto RETRY;
 }

 • Don‟t...
NOWDOC

Repeat after me, exactly as I say it:
 $a = 3; $b = 5;
 echo <<<EOF
 $a+$b
 EOF;     // prints 3+5
 echo <<<„EOF‟
...
__DIR__

__FILE__‟s brother – constant dirname(__FILE__)

 class Foo {
    const BAR = dirname(__FILE__); // can‟t!
    co...
Phar


  • Packs multiple PHP files into one .phar
  • Supports streams & includes into phar
  • Supports running CLI and ...
ICU extension


  • Supports internationalization functions from IBM
      ICU
  •   Collation (plain English: sorting)
  ...
INI improvements


  • Localized sections:
      [PATH=/var/www/html/mysite]
      [HOST=www.myblog.com]
  • .htaccess-s...
MySQLnd


 •   PHP-specific MySQL client library
 •   Uses Zend MM
 •   Reduces copying of data
 •   Uses PHP streams
 •  ...
E_DEPRECATED


 • Functionality that will be removed in next versions




                                         What's ...
Other function improvements

• OpenSSL support for OpenID
     openssl_digest(), openssl_encrypt(), openssl_decrypt(), DH...
Garbage collector


  • Collects memory lost in loops
  • Invisible to the untrained eye
  • gc_collect_lops, gc_enable, g...
Performance


  • Bench.php



                              4.075
                                                       ...
Thank you!


  • Questions?




                 What's new in PHP 5.3 | 2-Apr-10 | 24
Upcoming SlideShare
Loading in...5
×

ZendCon 08 php 5.3

1,745

Published on

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

  • Be the first to like this

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

No notes for slide

ZendCon 08 php 5.3

  1. 1. What’s coming in PHP 5.3 By Stas Malyshev Copyright © 2007, Zend Technologies Inc.
  2. 2. 5.2 vs 5.3 vs 6 • 5.3 is a major version, should be 5½.0 • 6 taking long time, features drift back • No sudden moves in 5.x What's new in PHP 5.3 | 2-Apr-10 | 2
  3. 3. Syntax • Namespaces! • Late static binding (static::foo vs self::foo) • $classname::method() • __callstatic() • Goto • ?: • $NOWDOC = <<„END‟ • __DIR__ What's new in PHP 5.3 | 2-Apr-10 | 3
  4. 4. Functions • Phar – PHP Archive • Pect/intl – ICU support • MySQLnd • INI magic – per dir, per user, .htaccess-style • OpenSSL for OpenID • SPL class library • Date/time improvements • Getopt() support • E_DEPRECATED What's new in PHP 5.3 | 2-Apr-10 | 4
  5. 5. Engine • Garbage collection! • Stack usage improvements • Opcode optimizations • System call reduction What's new in PHP 5.3 | 2-Apr-10 | 5
  6. 6. Namespaces define(“MY_HTTP_GET”, 1); namespace My::Http; define(“MY_HTTP_POST”, 2); const GET = 1; const PUT = 2; class My_Http_Request { function __construct( class Request { $method = function __construct( ZEND_HTTP_GET) $method = GET) { { } } } } function send_request( Request $request) { function my_http_send_request( } My_Http_Request $request) { } What's new in PHP 5.3 | 2-Apr-10 | 6
  7. 7. Namespaces • Organize OO code into self-contained units • Reduce conflicts • Shorten names  class Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensiti ve extends Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum • Compile-time definition • Mostly compile-time resolution • Many NS per file, many files per NS • Real names have :: What's new in PHP 5.3 | 2-Apr-10 | 7
  8. 8. Namespaces – new syntax • namespace foo::bar; • use foo::bar as baz, boo::hoo::foo; • __NAMESPACE__ • namespace::foo • ::foo() - means global one What's new in PHP 5.3 | 2-Apr-10 | 8
  9. 9. Late Static Binding Gateway to ActiveRecord class Singleton { const ID = 0; static $instance = array(); static function getInstance() { $id = static::ID; if (empty(self::$instance[$id])) { self::$instance[$id] = new static; } return self::$instance[$id]; } } class Foo extends Singleton { const ID = 1; } $x = Foo::getInstance(); What's new in PHP 5.3 | 2-Apr-10 | 9
  10. 10. Dynamic class name Everything can be variable, class name too class DbDriver { const NAME = “MySQLDriver”; static function execute($sql) { } } $db = “DbDriver”; echo $db::NAME; $db::execute(“SELCT * FROM foo;”); What's new in PHP 5.3 | 2-Apr-10 | 10
  11. 11. __callStatic __call‟s static cousin class DummyDriver { const NAME = „Dummy‟; static function __callstatic($name, $args) { echo static::NAME.“::$name is not implemented”; } } class MySqlDriver extends DummyDriver { const NAME = „MySQL‟; } $db = „MySqlDriver‟; $db::execute(„SELCT * FROM foo;‟); What's new in PHP 5.3 | 2-Apr-10 | 11
  12. 12. ?: Shortcut for $a?$a:$b $name = $_GET[„name‟] ?: „anonymous‟; What's new in PHP 5.3 | 2-Apr-10 | 12
  13. 13. goto Guess what it does ;) RETRY: try { … } catch (Exception $e) { recovery($e); goto RETRY; } • Don‟t try it at home – unless you know what you do • Can‟t jump into blocks What's new in PHP 5.3 | 2-Apr-10 | 13
  14. 14. NOWDOC Repeat after me, exactly as I say it: $a = 3; $b = 5; echo <<<EOF $a+$b EOF; // prints 3+5 echo <<<„EOF‟ $a+$b EOF; // prints $a+$b echo <<<“EOF” $a+$b EOF; // printd 3+5 Note HEREDOC has two syntaxes now What's new in PHP 5.3 | 2-Apr-10 | 14
  15. 15. __DIR__ __FILE__‟s brother – constant dirname(__FILE__) class Foo { const BAR = dirname(__FILE__); // can‟t! const BAR = __DIR__; public $bar = dirname(__FILE__); // can‟t! public $bar = __DIR__; } What's new in PHP 5.3 | 2-Apr-10 | 15
  16. 16. Phar • Packs multiple PHP files into one .phar • Supports streams & includes into phar • Supports running CLI and Web apps from phar include „phar://mylib.phar/My/Http.php‟; $img = „phar://mylib.phar/My/img/logo.jpg‟; header(„Content-type: image/jpeg‟); echo file_get_contents($img); What's new in PHP 5.3 | 2-Apr-10 | 16
  17. 17. ICU extension • Supports internationalization functions from IBM ICU • Collation (plain English: sorting) • Number/Date/Message formatting • Locale representation • Normalization • Graphemes What's new in PHP 5.3 | 2-Apr-10 | 17
  18. 18. INI improvements • Localized sections:  [PATH=/var/www/html/mysite]  [HOST=www.myblog.com] • .htaccess-style user files  user_ini.filename = “.user.ini”  user_ini.cache_ttl = 300 What's new in PHP 5.3 | 2-Apr-10 | 18
  19. 19. MySQLnd • PHP-specific MySQL client library • Uses Zend MM • Reduces copying of data • Uses PHP streams • --with-mysql=mysqlnd What's new in PHP 5.3 | 2-Apr-10 | 19
  20. 20. E_DEPRECATED • Functionality that will be removed in next versions What's new in PHP 5.3 | 2-Apr-10 | 20
  21. 21. Other function improvements • OpenSSL support for OpenID  openssl_digest(), openssl_encrypt(), openssl_decrypt(), DH key exchange • Getopt() on all OSes with –support-long-options • Faster md5() • OCI8 connection pooling • SPL class library additions:  DoublyLinkedList, Stack, Queue, PriorityQueue, Heap  FilesystemIterator, GlobIterator • Date/time improvements  date_create_from_format(), date_get_last_errors() What's new in PHP 5.3 | 2-Apr-10 | 21
  22. 22. Garbage collector • Collects memory lost in loops • Invisible to the untrained eye • gc_collect_lops, gc_enable, gc_disable $a = array(); $a[0] =& $a; What's new in PHP 5.3 | 2-Apr-10 | 22
  23. 23. Performance • Bench.php 4.075 php 5.3 PHP version 5.577 php 5.2 5.38 php 5.1 13.415 php 5.0 php 4.4 14.443 0 2 4 6 8 10 12 14 16 sec What's new in PHP 5.3 | 2-Apr-10 | 23
  24. 24. Thank you! • Questions? What's new in PHP 5.3 | 2-Apr-10 | 24
  1. Gostou de algum slide específico?

    Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

×