Migrating to PHP 5.3

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    5 Favorites & 1 Group

    Migrating to PHP 5.3 - Presentation Transcript

    1. Migrating to PHP 5.3 Stefan Priebsch July 31st 2009 Copyright © 2009 thePHP.cc, Germany
    2. Premium PHP Consulting & Training. Worldwide. Sebastian Arne Stefan Bergmann Blankerts Priebsch
    3. Why PHP 5.3?  Faster  Better tested  Officially supported on all Windows platforms  Loads of new features
    4. Selected PHP 5.3 Highlights  Namespaces  Late Static Binding  New extensions: fileinfo, intl, Phar  New datastructures in SPL  SQLite3  mysqlnd  Garbage Collection
    5. Namespaces  Work for classes, functions and constants  Namespace separator:  Work like directory navigation  Relative Path namespace foobar + class baz = foobarbaz namespace foo + class barbaz = foobarbaz  Absolute Path namespace foobar + class baz = baz  Prepend built-in classes and functions with  throw new Exception  strlen(...)
    6. Namespaces Example namespace myApplicationModels; use FrameworkModelModelBase as Model; class UserModel extends Model { ... }
    7. Late Static Binding Example class BaseClass { static protected $foo = 'foo'; static public function getFoo() { return self::$foo; } } var_dump(BaseClass::getFoo()); Will output: string(3) "foo"
    8. Late Static Binding Example class SubClass extends BaseClass { static protected $foo = 'bar'; } var_dump(SubClass::getFoo()); Will output: string(3) "foo"
    9. Late Static Binding Example class BaseClass { static protected $foo = 'foo'; static public function getFoo() { return static::$foo; } } var_dump(SubClass::getFoo()); Will output: string(3) "bar"
    10. Late Static Binding Example class SomeClass { static public function foo() { var_dump('foo method'); } } $classname = 'SomeClass'; $classname::foo(); Will output: string(10) "foo method"
    11. Phar  PHP Archive  Stream wrapper-based PHP extension + Userland implementation  Can be executable  No temporary files involved  php.ini: phar.readonly=Off; You cannot set this at runtime!
    12. Phar Example src/: ... any files ... stub.php: Phar::mapPhar('alias.phar'); ... __HALT_COMPILER(); create_phar.php: $phar = new Phar('executable.phar'); $phar->buildFromDirectory('./src'); $phar->setStub( file_get_contents('./stub.php'));
    13. Migration Problems  Environment  Old Extensions  Compile-time errors  Name Conflicts  More strictness  Runtime errors  New error messages (E_DEPRECATED)  Logic errors  Altered behaviour
    14. Altered function behaviour $haystack = 'hello world'; $needle = 'lo'; var_dump(strrpos($haystack, $needle));
    15. Altered function behaviour $haystack = 'hello world'; $needle = 'lo'; var_dump(strrpos($haystack, $needle)); PHP 4: int(9)
    16. Altered function behaviour $haystack = 'hello world'; $needle = 'lo'; var_dump(strrpos($haystack, $needle)); PHP 4: int(9) PHP 5: int(3)
    17. Solution: Create a wrapper function strrpos_wrapper($haystack, $needle, $offset = 0) { return strrpos($haystack, substr($needle, 0, 1), $offset); }
    18. More Strictness abstract class Test { abstract static function foo(); } Strict standards: Static function should not be abstract
    19. More Strictness abstract class Test { abstract private function foo(); } Fatal error: Abstract function cannot be declared private
    20. Useful Tools  Lint: php -l  Validators (HTML, XML, CSS, JS)  PHPUnit  http://www.phpunit.de  Selenium  http://seleniumhq.org  xdebug  http://www.xdebug.org
    21. xdebug Function Trace
    22. Mocking include_once './library/function.php'; for($i = 0; $i < 5; $i++) { var_dump(get_random_value()); } library/function.php: function get_random_value() { return rand(1, 10); }
    23. Mocking mock_library/function.php: function get_random_value() { static $i = 0; static $random_values = array(1, 2, 3, 4, 5); return $random_values[$i++]; }
    24. Mocking include_once './mock_library/function.php'; for($i = 0; $i < 5; $i++) { var_dump(get_random_value()); }
    25. How To Migrate  Fix errors/warnings/notices  Normalize the PHP configuration  Set up two test systems, old and new  Do A/B testing  Compare the results  Fix the problems  Switch the production system
    26. Future­Proof PHP Configuration  ze1.compatibility_mode=Off  allow_call_time_pass_reference=Off  register_globals=Off  magic_quotes_*=Off  register_long_arrays=Off
    27. http://www.phparch.com/books/index
    28. Code Works '09 Workshops  ”Advanced OOP and Design Patterns”  ”PHP Code Review” with Arne Blankerts and Sebastian Bergmann http://cw.mtacon.com
    29. Thank You. ■ http://thePHP.cc ■ http://www.priebsch.de ■ http://www.slideshare.net/spriebsch ■ http://twitter.com/spriebsch ■ stefan@thePHP.cc, IRC: spriebsch Copyright © 2009 thePHP.cc, Germany

    + Stefan PriebschStefan Priebsch, 3 months ago

    custom

    1808 views, 5 favs, 6 embeds more stats

    PHP 5.3 is here! Just install it and enjoy its new more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1808
      • 1252 on SlideShare
      • 556 from embeds
    • Comments 0
    • Favorites 5
    • Downloads 52
    Most viewed embeds
    • 478 views on http://www.priebsch.de
    • 30 views on http://www.3wstudio.com.ar
    • 29 views on http://it-republik.de
    • 15 views on http://entwickler.com
    • 3 views on http://entwickler.de

    more

    All embeds
    • 478 views on http://www.priebsch.de
    • 30 views on http://www.3wstudio.com.ar
    • 29 views on http://it-republik.de
    • 15 views on http://entwickler.com
    • 3 views on http://entwickler.de
    • 1 views on http://phpmagazin.de

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events