new stuff in php 5.3

Download New Stuff In Php 5.3

If you can't read please download the document

Upload: chris-chubb

Post on 26-Jun-2015

1.297 views

Category:

Technology


0 download

DESCRIPTION

An overview of new stuff in PHP 5.3 and some migration issues from earlier versions.

TRANSCRIPT

  • 1. What's New In PHP 5.3 Chris Chubb, Code Gurus www.codegurus.com [email_address]

2. Migrating from PHP 5.2.x to PHP 5.3.x

  • http://us.php.net/manual/en/migration53.php 3. See other guides for 4.x -> 5 or 5.1 -> 5.2 4. Some of these items are things that are new to 5.2, but of interest because 5.3 has modified their implementation.

5. Backward Incompatible Changes

  • Object._toString()
    • used for string casting everywhere, so you can override it, in fact you MUST if you want to use it for any place you may treat an object like a string, like in an echo DEBUG statement. Objects still can't be indices of arrays though, for that you must provide your own unique instance hash or call spl_object_hash(), even if you know it's unique. (Or fake it out with an explicit string cast: $array[(string)$object])
  • realpath() is now fully platform independent.

6. Deprecations (2)

  • You must now specifically cast objects as an array to use them in the array sort functions. (Do this anyway...) 7. magic methods __get, __set, __isset, __unset, and __call must always be public and can no longer be static. 8. The __call magic method is now invoked on access to private and protected methods. (Not just public any more. Self __call)

9. Deprecations (2)

  • Oracle extension now requires at least Oracle 10. (I think this is a bad idea, too many legacy Oracle installations) 10. 'goto' and 'namespace' are now reserved words. Do a string search in your code. More on these later

11. New stuff

  • Many new more descriptive error messages, especially with class handling. 12. Date object moved into the core, and all supporting functions have also become objects. Timezone is inspected more for intervals, etc.

13. Functions with new optional parameters

  • http://us.php.net/manual/en/migration52.parameters.php 14. Highlights:
    • datetime can now do milliseconds in the format 15. cookie functions take "httponly" so they can't be accessed by XSS attacks. 16. xmlreader now lets you set the encoding directly for reading. No more stream encoding manually.

17. New Functions

  • http://us.php.net/manual/en/migration52.functions.php 18. Highlights:
    • error_get_last - Just get the last error info as an assoc array 19. Multibyte string handling functions. For you UTF-8 guys.

20. Namespaces

  • http://us.php.net/manual/en/language.namespaces.php 21. Use to encapsulate classes and variables to prevent naming collisions on large projects. 22. Namespaces are declared using the namespace keyword. A file containing a namespace must declare the namespace at the top of the file before any other code - with one exception: the declare keyword. No non-PHP code either, so don't use it with embedded PHP. 23. Sub-namespace with backslashes:namespace MyProjectSubLevel;

24. Namespaces (2)

  • Namespaces may be single-line versions: 25. namespace ThisNamespace; //Continue to end of file or next namespace directive 26. or multi-line versions 27. namespace ThisNamespace { //Put your classes and variables in here } 28. Global namespace code may be put in a unnamed bracketed section. 29. namespace { //Global code }

30. Namespaces (3)

  • Reference namespace using directory-like naming. Use single backslash to call a global function, even if a local function of the same name exists. 31. 'use' will import a namespace into the current namespace and the 'as' clause can be used to alias it. 32. Note: Nested namespaces are not allowed. 33. Note: Cannot create local versions of the constants NULL, TRUE or FALSE. Do not "define(TRUE, 0);" for you jokers out there.

34. Late Static Bindings

  • http://us.php.net/manual/en/language.oop5.late-static-bindings.php 35. "self::" - Static references to the current class like self:: or __CLASS__ are resolved using the class in which the function belongs, as in where it was defined 36. "static::" - Replaces reference with run-time definition, so a subclass instance will use the current child class instead of the parent class.

37. Goto Operator === Evil

  • goto a; echo 'Foo'; a: echo 'Bar'; 38. Enough said.

39. Anonymous Functions (Closures)

  • http://us.php.net/manual/en/functions.anonymous.php 40. Use an unnamed function as the parameter for a callback function to keep code readable and not worry about namespace collisions. 41. Can also assign an anonymous function to a variable and call like "$function($param);" 42. Anon functions may inherit certain variables from their parent "calling" stack with the "use" operator.

43. Two new "magic" functions

  • __invoke
    • When an object is being called like a function.
  • __callStatic
    • Like __call but for inaccessible static functions.

44. NEWDOC String Declaration

  • Like Heredoc, but treated like a single quoted string. No parsing.
    • $string=