1 / 26

New Features in PHP5

New Features in PHP5. Paul F. Gilzow Web Communications. Backward Incompatible Changes. array_merge () only accepts arrays strrpos () and strripos () now use the entire string as a needle

elom
Download Presentation

New Features in PHP5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. New Features in PHP5 Paul F. Gilzow Web Communications

  2. Backward Incompatible Changes • array_merge() only accepts arrays • strrpos() and strripos() now use the entire string as a needle • get_class(), get_parent_class() and get_class_methods() now return the name of the classes/methods as they were declared (case-sensitive) • An object with no properties is no longer considered "empty"

  3. Backward Incompatible Changes cont. • New reserved keywords

  4. New Features • Exceptions • SimpleXML • DOM • Objects • SQLite Support • PDO • Reflection Class • JSON Support • New Functions

  5. Exceptions • PHP5 introduces exceptions using a Java-like syntax: try, catch, throw • All exceptions extend the standard Exception class, so custom exceptions are possible

  6. SimpleXML • Very simple, built-in XML parser • Converts XML to an object that can be processed with normal property selectors and array iterators

  7. DOM DOM is a complete rewrite of the DOMXML extension. The new extensions makes use of PHP 5's OO features. • DOM Level 3 Load and Save Support • XPath • Validation support • NamedNodeMap support • Complete Namespaces support • Interop with SimpleXML and XSLT • HTML Support

  8. Objects • Referencing • Clone() • Access Controls • Constructor and Destructor • Class constants • Getters and setters • Class Constants (aka class-level defines)

  9. Object Referencing • In PHP4, if you pass an object to function, it would create an internal copy. In order to access the object, you would have to pass it in by reference. • In PHP5, objects are automatically referenced

  10. Object Cloning • Use the clone keyword to make a copy of an object

  11. Object Access Controls • In PHP4, there was no concept of object property protection. Any chunk of code could modify a member variable’s value • PHP5 introduces the following access controls to both methods and properties • Public • Protected • Private

  12. Object Access Controls - Public • This was default for all methods and properties in PHP4 • Accessible everywhere

  13. Object Access Controls - Protected • Limits access to • The class that defines them • Inherited classes • Parent classes

  14. Object Access Controls - Private • 'Strongest' access level • Can only be accessed/called from the same class • Force use of get()/set() functions to access properties

  15. Objects – Constructors/Destructors • Unified constructor name: __construct() • In PHP4 the constructor was named the same as the class • Unified destructor name: __desctruct() • Destructor method is called when all references to the object are removed, when the object is explicitly destroyed, or in script shutdown • Destructors called during the script shutdown have HTTP headers already sent. • Attempting to throw an exception from a destructor (called in the time of script termination) causes a fatal error

  16. Objects – Class Constants • Supports declaring class-specific constant values • Similar to define in PHP4

  17. SQLite • SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine • Bundled with PHP5 • Fast and easy interface to ‘flat file’ • SQL 99 subset

  18. PDO • PHP Data Objects • A lightweight set of PHP extensions that provide a core PDO class and database specific drivers • Creates a unified interface for creating and maintaining database connections, issuing queries, quoting parameters, traversing result sets, dealing with prepared statements and error handling • PDO provides a data-access abstraction layer, which means that regardless of which database you are using, you use the same functions to issue queries and fetch data

  19. PDO – What Can It Do? • Prepare/execute, bind parameters • Transactions • LOBs • Flexible error handling • Smooth over database specific nuances

  20. PDO – Supported Databases • Oracle • MSSQL • MySQL • PostgreSQL • SQLite • ODBC/DB2 • Firebird/Interbase

  21. Reflection • Also referred to as “Introspection” • Provides the ability to reverse-engineer • Classes • Interfaces • Functions • Methods • Extensions • Also provides method to retrieve doc comments

  22. JSON Support • Javascript Object Notation data-interchange format encoder/decoder • As of PHP 5.2.0, the JSON extension is bundled and compiled into PHP by default • Can decode a JSON string to a PHP object or associative array • Can encode any PHP type (except resource) into a JSON encoded string

  23. New Functions - Array • array_combine() - Creates an array by using one array for keys and another for its values • array_diff_uassoc() - Computes the difference of arrays with additional index check which is performed by a user supplied callback function • array_udiff() - Computes the difference of arrays by using a callback function for data comparison • array_uintersect_assoc() - Computes the intersection of arrays with additional index check. The data is compared by using a callback function • array_uintersect_uassoc() - Computes the intersection of arrays with additional index check. Both the data and the indexes are compared by using separate callback functions

  24. New Functions – Date/Time related • DateTime() – OO API to date/time • Date_default_timezone_get()/set() – Gets/Sets the default timezone used by all date/time functions in a script • idate() - Format a local time/date as integer • date_sunset() - Time of sunset for a given day and location • date_sunrise() - Time of sunrise for a given day and location • time_nanosleep() - Delay for a number of seconds and nanoseconds

  25. New Functions - Misc • __autoload() • php_check_syntax()

  26. PHP5 On Campus • The Division of IT is working on a plan to upgrade the Departmental Web Hosting Service to the latest release of Red Hat Enterprise which includes PHP5.  The steps required are: • Upgrade the Virtual Host Development server and allow departments up to 30 days to test their pages and applications to ensure they work properly with the new operating system and PHP5 • Schedule a service outage and upgrade the production servers • If code or application modifications are required, departmental users will move their changes from development to production after the upgrade outage • Given that the next logical time frame for the production upgrade is Christmas break/intercession, we would like to have this entire process completed after December 19 but no later than January 18, 2009.  That means we can start the upgrade on the development server in November.

More Related