You are previewing Upgrading to PHP 5.
O'Reilly logo
Upgrading to PHP 5

Book Description

If you're using PHP 4, then chances are good that an upgrade to PHP 5 is in your future. The more you've heard about the exciting new features in PHP 5, the sooner that upgrade is probably going to be. Although an in-depth, soup-to-nuts reference guide to the language is good to have on hand, it's not the book an experienced PHP programmer needs to get started with the latest release. What you need is a lean and focused guide that answers your most pressing questions: what's new with the technology, what's different, and how do I make the best use of it? In other words, you need a copy of Upgrading to PHP 5. This book is targeted toward PHP developers who are already familiar with PHP 4. Rather than serve as a definitive guide to the entire language, the book zeroes in on PHP 5's new features, and covers these features definitively. You'll find a concise appraisal of the differences between PHP 4 and PHP 5, a detailed look at what's new in this latest version, and you'll see how PHP 5 improves on PHP 4 code. See PHP 4 and PHP 5 code side-by-side, to learn how the new features make it easier to solve common PHP problems. Each new feature is shown in code, helping you understand why it's there, when to use it, and how it's better than PHP 4. Short, sample programs are included throughout the book. Topics covered in Upgrading to PHP 5 include:

  • The new set of robust object-oriented programming features

  • An improved MySQL extension, supporting MySQL 4.1, prepared statements, and bound parameters

  • Completely rewritten support for XML: DOM, XSLT, SAX, and SimpleXML

  • Easy web services with SOAP

  • SQLite, an embedded database library bundled with PHP 5

  • Cleaner error handling with exceptions

  • Other new language features, such as iterators, streams, and more.

  • Upgrading to PHP 5 won't make you wade through information you've covered before. Written by Adam Trachtenberg, coauthor of the popular PHP Cookbook, this book will take you straight into the heart of all that's new in PHP 5. By the time you've finished, you'll know PHP 5 in practice as well as in theory.

    Table of Contents

    1. Upgrading to PHP 5
      1. Preface
        1. Who This Book Is For
        2. Who This Book Is Not For
        3. What’s in This Book
        4. Other Resources
          1. Web Sites
          2. Books
        5. Conventions Used in This Book
          1. Programming Conventions
          2. Typesetting Conventions
        6. Using Code Examples
        7. We’d Like to Hear from You
        8. Acknowledgements
      2. 1. Introduction
        1. Why PHP 5?
        2. What’s New in PHP 5?
          1. MySQL
          2. SQLite
          3. XML
          4. Iterators and SPL
          5. Error Handling and Debugging
          6. Streams, Filters, and Wrappers
          7. Other Extensions
          8. PHP 5 in Action
          9. Everything Else
        3. Installing and Configuring PHP 5
      3. 2. Object-Oriented Programming
        1. What Is Object-Oriented Programming?
          1. Using Objects
          2. Autoload
          3. Data Encapsulation
          4. Constructors and Destructors
        2. Memory Management
          1. Object References
          2. Garbage Collection
        3. Basic Classes
          1. Properties
          2. Methods
          3. Access Restrictions
          4. Constructors and Destructors
        4. Class Intermediates
          1. Interfaces
          2. Type Hinting
          3. Static Methods and Properties
        5. Inheritance
          1. Extending Classes
          2. Class Hierarchies
          3. Abstract Classes
          4. Constructors
          5. Final Classes, Methods, and Properties
        6. Magical Methods
          1. _ _get( ) and _ _set( )
          2. _ _call( )
          3. _ _toString( )
          4. _ _clone( )
      4. 3. MySQL
        1. Installing and Configuring
        2. Procedural Interface
          1. Alternative Fetch Methods
        3. Before and After: Connecting to the Database Server
          1. mysql: Making a Connection
          2. mysqli: Making a Connection
        4. Object-Oriented Interface
        5. Before and After: Querying and Retrieving Data with Prepared Statements
          1. PHP 4: Traditional Input Queries
          2. PHP 5: Binding Input Parameters
          3. PHP 5: Binding Input Parameters with Multiple Queries
          4. PHP 5: Binding Output Parameters
          5. PHP 5: Bound Input and Output Parameters
          6. Object-Oriented Interface
        6. Before and After: Subselects
          1. MySQL 4.0: Finding Related Entries
          2. MySQL 4.1: Finding Related Entries
          3. When Subselects Are Necessary
        7. Transactions
          1. Creating Transaction-Supported Tables
          2. Using Transactions
          3. AUTOCOMMIT
        8. Before and After: Making Multiple Queries
          1. mysql: Making Multiple Queries
          2. mysqli: Making Multiple Queries
        9. Securing Connections with SSL
        10. Porting Code and Migrating Databases
          1. Migration Paths
            1. Don’t migrate anything
            2. Migrate only to MySQL 4.1
            3. Migrate to MySQL 4.1 and PHP 5
            4. Complete migration to MySQL 4.1, PHP 5, and mysqli
            5. Making the right decision
          2. Migration Plan of Attack
            1. Step 1: Migrating from MySQL 3.2.x or MySQL 4.0.x to MySQL 4.1.2
            2. Step 2: Porting to PHP 5
            3. Step 3: Migrating to mysqli
            4. Adding new features
      5. 4. SQLite
        1. SQLite Basics
          1. Inserting Data
          2. Retrieving Data
          3. SQLite Versus MySQL
        2. Alternate SQLite Result Types
        3. Object-Oriented Interface
          1. Using the SQLiteDatabase Object
          2. Object Iterators
        4. Indexes, Error Handling, and In-Memory Tables
          1. Indexes
          2. Primary Keys
          3. Error Handling
            1. Procedural error handling
            2. Object-oriented error handling
          4. In-Memory Tables
        5. Transactions
        6. User-Defined Functions
          1. Standard Functions
          2. User-Defined Aggregate Functions
          3. Binary Data
      6. 5. XML
        1. XML Extensions in PHP 5
        2. Installing XML and XSLT Support
        3. DOM
          1. About DOM
          2. Turning XML Documents into DOM objects
          3. DOM Nodes
            1. Accessing the root element
            2. Navigating through nodes
            3. Determining node types
            4. Accessing text nodes
            5. Accessing element nodes
          4. Turning DOM Objects into XML Documents
        4. SimpleXML
          1. Turning XML Documents into SimpleXML Objects
          2. SimpleXML Elements
          3. Turning SimpleXML Objects into XML Documents
        5. Converting Between SimpleXML and DOM Objects
        6. Before and After: Reading XML into a Tree
          1. Reading an Address Book
            1. PHP 4 and DOM
            2. PHP 5 and DOM
            3. PHP 5 and SimpleXML
          2. Reading an Address Book with Namespaces
            1. PHP 4 and DOM
            2. PHP 5 and DOM
            3. PHP 5 and SimpleXML
        7. Before and After: Searching XML with XPath
          1. Reading an Address Book
            1. PHP 4 and DOM
            2. PHP 5 and DOM
            3. PHP 5 and SimpleXML
          2. Reading an Address Book with Namespaces
            1. PHP 4 and DOM
            2. PHP 5 and DOM
            3. PHP 5 and SimpleXML
        8. Reading XML as Events with SAX
        9. Before and After: Creating New XML Documents
          1. Creating an Address Book
            1. PHP 4 and DOM
            2. PHP 5 and DOM
        10. Before and After: Transforming XML with XSLT
          1. PHP 4
          2. PHP 5
          3. Setting Parameters
          4. Calling PHP Functions from Stylesheets
        11. Validating Against a Schema
          1. PHP 5 and DOM
      7. 6. Iterators and SPL
        1. Before and After: Using Iterators
          1. PHP 4: Reading Files in a Directory
          2. PHP 5: Reading Files in a Directory
          3. DirectoryIterator Methods
        2. Implementing the Iterator Interface
        3. MySQL Query Iterator
        4. Chaining Iterators
          1. Filtering Results with FilterIterator
          2. Limiting Results with LimitIterator
        5. SimpleXML Iterator
        6. Before and After: Recursive Directory Iteration
          1. PHP 4: Recursively Reading Files in a Directory
          2. PHP 5: Recursively Reading Files in a Directory
        7. Implementing the RecursiveIterator Interface
        8. Array and Object Property Iteration
        9. Redefining Class Iteration
          1. Implementing IteratorAggregate
          2. Turning Arrays and Objects into Iterators
          3. Writing Dynamic Iterable Objects
        10. Iterator and SPL Classes and Interfaces
      8. 7. Error Handling and Debugging
        1. Before and After: Handling Errors
          1. PHP 4: Checking Return Values
          2. PHP 5: Catching Exceptions
        2. The Benefits of Exceptions
        3. System Exceptions
          1. Constructors
          2. Serious Problems
        4. The Exception Class
        5. User Exceptions
          1. When to Use Exceptions
          2. Throwing an Exception
          3. Writing and Catching Custom Exceptions
            1. Handling multiple exception types
            2. Embedding custom exception data
        6. Setting a Custom Exception Handler
        7. Processing Errors with a Custom Handler
        8. Debugging Functions
          1. Integrating Debugging into Your Code
          2. Redirecting Output to a File
      9. 8. Streams, Wrappers, and Filters
        1. Using the Streams API
        2. Wrapper Overview
          1. Bundled Wrappers
        3. Wrapper Details
          1. HTTP and HTTPS
          2. FTP and FTPS
          3. PHP Input and Output
            1. Standard input, output, and error
            2. General input and output
            3. Filtered input and output
          4. Compression
        4. Creating Wrappers
          1. Opening and Closing
          2. Reading and Writing
          3. Using ShmopWrapper
          4. Deleting
          5. Adding Context Options
          6. Other Methods
        5. Filtering Streams
          1. Stripping HTML Tags
          2. Converting Character Sets
          3. Using php://filter
        6. Creating Filters
          1. Converting to HTML Entities
          2. Converting from HTML Entities
      10. 9. Other Extensions
        1. SOAP
          1. WSDL
          2. Requesting Information with a SOAP Client
            1. WSDL requests
            2. Non-WSDL requests
            3. Multiple parameter queries
          3. Catching SOAP Faults
          4. Caching WSDL
          5. Processing Requests with a SOAP Server
            1. Implementing getTemp( ) in PHP
            2. Optional parameters
        2. Tidy
          1. Basics
          2. Configuring Tidy
          3. Optimize Files
          4. Object-Oriented Interface
        3. Reflection
          1. Getting an Overview with Reflection::export
          2. Inspecting Classes, Methods, and Properties
          3. Reflection Class Methods
      11. 10. PHP 5 in Action
        1. Defining Your Database Schema
        2. The Person Class
          1. Constructor
          2. Encapsulating Property Access with _ _get( ) and _ _set( )
          3. Enabling Custom Object Iteration with getIterator( )
          4. Converting a Person Object to an XML Document Using DOM
          5. Creating and Manipulating a Person Object
        3. The addressBook Class
          1. Constructor
          2. Adding a Person to an addressBook
          3. Searching for People Within an addressBook
          4. Converting an addressBook Object to an XML Document Using DOM
        4. The Template Class
          1. Creating an HTML Template
          2. Creating a Plain-Text Template
          3. Displaying Multiple Output Formats with a Template
        5. Assembling the Application
          1. Creating the Web Version
          2. Creating the Command-Line Version
          3. Creating a Unified Program
        6. Wrap-Up and Future Directions
      12. A. Introduction to XML
        1. Comparing HTML and XML
          1. Similarities
          2. Differences
            1. XML declarations
            2. Processing instructions
            3. Character Data sections
        2. Well-Formed XML
        3. Schemas
        4. Transformations
        5. XML Namespaces
          1. Why Use Namespaces?
          2. Syntax
          3. Namespace Prefixes
          4. Examples
          5. Default Namespaces
        6. XPath
      13. B. Additional New Features and Minor Changes
        1. Passing Optional Parameters by Reference
        2. New E_STRICT Error Setting
        3. Treating Strings as Arrays Causes Errors
        4. CLI Now Allows Individual Line Processing
        5. CLI Always Provides argv and argc
        6. Oracle (oci8) Extension Functions Renamed
        7. New Configuration Directives
        8. Updated COM Extension
        9. Apache 2 Correctly Sets PATH_TRANSLATED
        10. strrpos( ) Uses the Entire Needle
        11. Windows 95 Support Dropped
        12. old_function Eliminated
      14. C. Installing PHP 5 Alongside PHP 4
        1. General PHP 5 Configuration
          1. Basics
          2. Configuration Options
            1. XML
            2. Databases
            3. Other options
        2. Module and CGI
          1. Configuring PHP 5 as a CGI
          2. Directories
          3. Ports
        3. Windows
      15. Index
      16. Colophon