New Stuff In Php 5.3
Upcoming SlideShare
Loading in...5
×
 

New Stuff In Php 5.3

on

  • 1,940 views

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

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

Statistics

Views

Total Views
1,940
Slideshare-icon Views on SlideShare
1,937
Embed Views
3

Actions

Likes
0
Downloads
22
Comments
0

2 Embeds 3

http://www.linkedin.com 2
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    New Stuff In Php 5.3 New Stuff In Php 5.3 Presentation Transcript

    • What's New In PHP 5.3 Chris Chubb, Code Gurus www.codegurus.com [email_address]
    • Migrating from PHP 5.2.x to PHP 5.3.x
      • http://us.php.net/manual/en/migration53.php
      • See other guides for 4.x -> 5 or 5.1 -> 5.2
      • Some of these items are things that are new to 5.2, but of interest because 5.3 has modified their implementation.
    • 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.
    • Deprecations (2)
      • You must now specifically cast objects as an array to use them in the array sort functions. (Do this anyway...)
      • magic methods __get, __set, __isset, __unset, and __call must always be public and can no longer be static.
      • The __call magic method is now invoked on access to private and protected methods. (Not just public any more. Self __call)
    • Deprecations (2)
      • Oracle extension now requires at least Oracle 10. (I think this is a bad idea, too many legacy Oracle installations)
      • 'goto' and 'namespace' are now reserved words. Do a string search in your code. More on these later
    • New stuff
      • Many new more descriptive error messages, especially with class handling.
      • Date object moved into the core, and all supporting functions have also become objects. Timezone is inspected more for intervals, etc.
    • Functions with new optional parameters
      • http://us.php.net/manual/en/migration52.parameters.php
      • Highlights:
        • datetime can now do milliseconds in the format
        • cookie functions take "httponly" so they can't be accessed by XSS attacks.
        • xmlreader now lets you set the encoding directly for reading. No more stream encoding manually.
    • New Functions
      • http://us.php.net/manual/en/migration52.functions.php
      • Highlights:
        • error_get_last - Just get the last error info as an assoc array
        • Multibyte string handling functions. For you UTF-8 guys.
    • Namespaces
      • http://us.php.net/manual/en/language.namespaces.php
      • Use to encapsulate classes and variables to prevent naming collisions on large projects.
      • 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.
      • Sub-namespace with backslashes: namespace MyProjectSubLevel;
    • Namespaces (2)
      • Namespaces may be single-line versions:
      • namespace ThisNamespace; //Continue to end of file or next namespace directive
      • or multi-line versions
      • namespace ThisNamespace { //Put your classes and variables in here }
      • Global namespace code may be put in a unnamed bracketed section.
      • namespace { //Global code }
    • 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.
      • 'use' will import a namespace into the current namespace and the 'as' clause can be used to alias it.
      • Note: Nested namespaces are not allowed.
      • Note: Cannot create local versions of the constants NULL, TRUE or FALSE. Do not "define(TRUE, 0);" for you jokers out there.
    • Late Static Bindings
      • http://us.php.net/manual/en/language.oop5.late-static-bindings.php
      • "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
      • "static::" - Replaces reference with run-time definition, so a subclass instance will use the current child class instead of the parent class.
    • Goto Operator === Evil
      • goto a; echo 'Foo'; a: echo 'Bar';
      • Enough said.
    • Anonymous Functions (Closures)
      • http://us.php.net/manual/en/functions.anonymous.php
      • Use an unnamed function as the parameter for a callback function to keep code readable and not worry about namespace collisions.
      • Can also assign an anonymous function to a variable and call like "$function($param);"
      • Anon functions may inherit certain variables from their parent "calling" stack with the "use" operator.
    • Two new "magic" functions
      • __invoke
        • When an object is being called like a function.
      • __callStatic
        • Like __call but for inaccessible static functions.
    • NEWDOC String Declaration
      • Like Heredoc, but treated like a single quoted string. No parsing.
        • $string=<<'ENDOFSTRING' Blah &quot;costs&quot; $20.00 ENDOFSTRING;
      • Heredoc may now be defined with double quotes. I recommend this to increase readability.
    • Const Declaration
      • You can now use &quot;const&quot; outside of a class as a synonym of &quot;define&quot;.