rent-now

Rent More, Save More! Use code: ECRENTAL

5% off 1 book, 7% off 2 books, 10% off 3+ books

9780131471498

PHP 5 Power Programming

by ; ;
  • ISBN13:

    9780131471498

  • ISBN10:

    013147149X

  • Edition: 1st
  • Format: Paperback
  • Copyright: 2004-10-27
  • Publisher: Prentice Hall
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $48.99

Summary

Written by the authors of the actual PHP code! The authoritative developer's guide to mastering advanced PHP 5 techniques.

Author Biography

Andi Gutmans co-created PHP 3 and all versions since Stig Saether Bakken a member of the PHP core team Derick Rethans is a PHP code contributor and leader of the PHP team

Table of Contents

Foreword xxi
Preface xxii
What Is New in PHP 5?
1(12)
Introduction
1(1)
Language Features
1(7)
New Object-Oriented Model
1(2)
New Object-Oriented Features
3(4)
Other New Language Features
7(1)
General PHP Changes
8(3)
XML and Web Services
8(3)
Other New Features in PHP 5
11(1)
New Memory Manager
11(1)
Dropped Support for Windows 95
11(1)
Summary
11(2)
PHP 5 Basic Language
13(42)
Introduction
13(1)
HTML Embedding
14(1)
Comments
14(1)
Variables
15(3)
Indirect References to Variables
16(1)
Managing Variables
16(2)
Superglobals
18(1)
Basic Data Types
18(13)
Integers
19(1)
Floating-Point Numbers
19(1)
Strings
19(3)
Booleans
22(1)
Null
23(1)
Resources
23(1)
Arrays
23(7)
Constants
30(1)
Operators
31(8)
Binary Operators
32(1)
Assignment Operators
32(1)
Comparison Operators
33(1)
Logical Operators
34(1)
Bitwise Operators
35(1)
Unary Operators
36(1)
Negation Operators
36(1)
Increment/Decrement Operators
37(1)
The Cast Operators
38(1)
The Silence Operator
39(1)
The One and Only Ternary Operator
39(1)
Control Structures
39(9)
Conditional Control Structures
39(3)
Loop Control Structures
42(3)
Code Inclusion Control Structures
45(3)
Functions
48(6)
User-Defined Functions
49(1)
Function Scope
49(1)
Returning Values By Value
50(1)
Returning Values By Reference
51(1)
Declaring Function Parameters
52(1)
Static Variables
53(1)
Summary
54(1)
PHP 5 OO Language
55(30)
Introduction
55(1)
Objects
55(2)
Declaring a Class
57(1)
The new Keyword and Constructors
57(1)
Destructors
58(1)
Accessing Methods and Properties Using the $this Variable
59(6)
public, protected, and private Properties
60(1)
public, protected, and private Methods
61(1)
Static Properties
62(2)
Static Methods
64(1)
Class Constants
65(1)
Cloning Objects
66(1)
Polymorphism
67(3)
parent:: and self::
70(1)
instanceof Operator
71(1)
Abstract Methods and Classes
72(1)
Interfaces
73(2)
Inheritance of Interfaces
75(1)
final Methods
75(1)
final Classes
76(1)
__toString() Method
76(1)
Exception Handling
77(3)
__autoload()
80(2)
Class Type Hints in Function Parameters
82(1)
Summary
83(2)
PHP 5 Advanced OOP and Design Patterns
85(26)
Introduction
85(1)
Overloading Capabilities
85(4)
Property and Method Overloading
85(3)
Overloading the Array Access Syntax
88(1)
Iterators
89(5)
Design Patterns
94(9)
Strategy Pattern
95(2)
Singleton Pattern
97(1)
Factory Pattern
98(3)
Observer Pattern
101(2)
Reflection
103(6)
Introduction
103(1)
Reflection API
103(3)
Reflection Examples
106(1)
Implementing the Delegation Pattern Using Reflection
107(2)
Summary
109(2)
How to Write a Web Application with PHP
111(38)
Introduction
111(1)
Embedding into HTML
112(2)
User Input
114(3)
Safe-Handling User Input
117(3)
Common Mistakes
117(3)
Techniques to Make Scripts ``Safe''
120(11)
Input Validation
120(2)
HMAC Verification
122(2)
PEAR::Crypt_HMAC
124(3)
Input Filter
127(1)
Working with Passwords
127(2)
Error Handling
129(2)
Cookies
131(3)
Sessions
134(3)
File Uploads
137(6)
Handling the Incoming Uploaded File
138(5)
Architecture
143(3)
One Script Serves All
143(1)
One Script per Function
144(1)
Separating Logic from Layout
144(2)
Summary
146(3)
Databases with PHP 5
149(42)
Introduction
149(1)
MySQL
149(11)
MySQL Strengths and Weaknesses
150(1)
PHP Interface
150(1)
Example Data
151(1)
Connections
151(2)
Buffered Versus Unbuffered Queries
153(1)
Queries
154(1)
Multi Statements
155(1)
Fetching Modes
156(1)
Prepared Statements
156(2)
BLOB Handling
158(2)
SQLite
160(16)
SQLite Strengths and Weaknesses
160(1)
Best Areas of Use
161(1)
PHP Interface
162(14)
PEAR DB
176(14)
Obtaining PEAR DB
176(1)
Pros and Cons of Database Abstraction
177(1)
Which Features Are Abstracted?
177(1)
Database Connections
178(2)
Executing Queries
180(2)
Fetching Results
182(2)
Sequences
184(1)
Portability Features
185(1)
Abstracted Errors
186(2)
Convenience Methods
188(2)
Summary
190(1)
Error Handling
191(28)
Introduction
191(1)
Types of Errors
192(14)
Programming Errors
192(2)
Undefined Symbols
194(3)
Portability Errors
197(4)
Runtime Errors
201(1)
PHP Errors
201(5)
PEAR Errors
206(10)
The PEAR_Error Class
209(3)
Handling PEAR Errors
212(1)
PEAR Error Modes
213(1)
Graceful Handling
213(3)
Exceptions
216(2)
What Are Exceptions?
216(1)
try, catch, and throw
216(2)
Summary
218(1)
XML with PHP 5
219(42)
Introduction
219(1)
Vocabulary
220(2)
Parsing XML
222(9)
SAX
222(4)
DOM
226(5)
SimpleXML
231(3)
Creating a SimpleXML Object
232(1)
Browsing SimpleXML Objects
233(1)
Storing SimpleXML Objects
234(1)
PEAR
234(5)
XML_Tree
235(1)
XML_RSS
236(3)
Converting XML
239(5)
XSLT
239(5)
Communicating with XML
244(15)
XML-RPC
244(8)
SOAP
252(7)
Summary
259(2)
Mainstream Extensions
261(84)
Introduction
261(1)
Files and Streams
261(18)
File Access
262(2)
Program Input/Output
264(3)
Input/Output Streams
267(1)
Compression Streams
268(2)
User Streams
270(1)
URL Streams
271(5)
Locking
276(1)
Renaming and Removing Files
277(1)
Temporary Files
278(1)
Regular Expressions
279(22)
Syntax
279(14)
Functions
293(8)
Date Handling
301(13)
Retrieving Date and Time Information
301(4)
Formatting Date and Time
305(8)
Parsing Date Formats
313(1)
Graphics Manipulation with GD
314(15)
Case 1: Bot-Proof Submission Forms
315(5)
Case 2: Bar Chart
320(6)
Exif
326(3)
Multi-Byte Strings and Character Sets
329(14)
Character Set Conversions
330(5)
Extra Functions Dealing with Multi-Byte Character Sets
335(5)
Locales
340(3)
Summary
343(2)
Using PEAR
345(38)
Introduction
345(1)
PEAR Concepts
346(3)
Packages
346(1)
Releases
346(1)
Version Numbers
347(2)
Obtaining PEAR
349(5)
Installing with UNIX / Linux PHP Distribution
350(1)
Installing with PHP Windows Installer
351(1)
go-pear.org
351(3)
Installing Packages
354(4)
Using the pear Command
354(4)
Configuration Parameters
358(6)
PEAR Commands
364(14)
pear install
364(4)
pear list
368(1)
pear info
369(1)
pear list-all
370(1)
pear list-upgrades
370(1)
pear upgrade
371(1)
pear upgrade-all
372(1)
pear uninstall
373(1)
pear search
373(1)
pear remote-list
374(1)
pear remote-info
375(1)
pear download
375(1)
pear config-get
376(1)
pear config-set
376(1)
pear config-show
376(1)
Shortcuts
377(1)
Installer Front-Ends
378(3)
CLI (Command Line Interface) Installer
378(1)
Gtk Installer
378(3)
Summary
381(2)
Important PEAR Packages
383(20)
Introduction
383(1)
Database Queries
383(1)
Template Systems
383(9)
Template Terminology
384(1)
HTML_Template_IT
384(3)
HTML_Template_Flexy
387(5)
Authentication
392(6)
Overview
392(1)
Example: Auth with Password File
393(1)
Example: Auth with DB and User Data
394(2)
Auth Security Considerations
396(1)
Auth Scalability Considerations
397(1)
Auth Summary
398(1)
Form Handling
398(1)
HTML_QuickForm
398(1)
Example: Login Form
399(1)
Receiving Data
399(1)
Caching
399(2)
Cache_Lite
399(2)
Summary
401(2)
Building PEAR Components
403(30)
Introduction
403(1)
PEAR Standards
403(5)
Symbol Naming
403(3)
Indentation
406(2)
Release Versioning
408(1)
CLI Environment
408(2)
Fundamentals
410(1)
When and How to Include Files
410(1)
Error Handling
411(1)
Building Packages
411(5)
PEAR Example: HelloWorld
411(3)
Building the Tarball
414(1)
Verification
414(2)
Regression Tests
416(1)
The package.xml Format
416(7)
Package Information
417(2)
Release Information
419(4)
Dependencies
423(4)
Element: <deps>
423(1)
Element: <dep>
423(1)
Dependency Types
424(1)
Reasons to Avoid Dependencies
425(1)
Optional Dependencies
426(1)
Some Examples
426(1)
String Substitutions
427(1)
Element: <replace>
427(1)
Examples
427(1)
Including C Code
428(1)
Element: <configureoptions>
428(1)
Element: <configureoption>
428(1)
Releasing Packages
428(1)
The PEAR Release Process
429(1)
Packaging
430(2)
Source Analysis
430(1)
MD5 Checksum Generation
430(1)
Package.xml Update
431(1)
Tarball Creation
431(1)
Uploading
432(1)
Upload Release
432(1)
Finished!
432(1)
Summary
432(1)
Making the Move
433(16)
Introduction
433(1)
The Object Model
433(1)
Passing Objects to Functions
433(2)
Compatibility Mode
435(2)
Casting Objects
435(1)
Comparing Objects
436(1)
Other Changes
437(4)
Assigning to $this
437(3)
get_class
440(1)
E_STRICT
441(2)
Automagically Creating Objects
441(1)
var and public
441(1)
Constructors
442(1)
Inherited Methods
442(1)
Define Classes Before Usage
443(1)
Other Compatibility Problems
443(2)
Command-Line Interface
443(1)
Comment Tokens
443(2)
MySQL
445(1)
Changes in Functions
445(2)
array_merge()
445(1)
strrpos () and strripos ()
446(1)
Summary
447(2)
Performance
449(34)
Introduction
449(1)
Design for Performance
449(8)
PHP Design Tip #1: Beware of State
450(1)
PHP Design Tip #2: Cache!
451(5)
PHP Design Tip #3: Do Not Over Design!
456(1)
Benchmarking
457(2)
Using ApacheBench
457(1)
Using Siege
458(1)
Testing Versus Real Traffic
459(1)
Profiling with Zend Studio's Profiler
459(2)
Profiling with APD
461(4)
Installing APD
461(1)
Analyzing Trace Data
462(3)
Profiling with Xdebug
465(5)
Installing Xdebug
466(1)
Tracing Script Execution
466(2)
Using KCachegrind
468(2)
Using APC (Advanced PHP Cache)
470(1)
Using ZPS (Zend Performance Suite)
470(7)
Automatic Optimization
471(1)
Compiled Code Caching
472(1)
Dynamic Content Caching
473(3)
Content Compression
476(1)
Optimizing Code
477(4)
Micro-Benchmarks
477(2)
Rewrite in C
479(1)
OO Versus Procedural Code
480(1)
Summary
481(2)
An Introduction to Writing PHP Extensions
483(24)
Introduction
483(1)
Quickstart
484(21)
Memory Management
489(1)
Returning Values from PHP Functions
490(1)
Completing self-concat ()
490(2)
Summary of Example
492(1)
Wrapping Third-Party Extensions
492(9)
Global Variables
501(2)
Adding Custom INI Directives
503(1)
Thread-Safe Resource Manager Macros
504(1)
Summary
505(2)
PHP Shell Scripting
507(20)
Introduction
507(1)
PHP CLI Shell Scripts
508(18)
How CLI Differs From CGI
508(2)
The Shell-Scripting Environment
510(2)
Parsing Command-Line Options
512(3)
Good Practices
515(1)
Process Control
516(4)
Examples
520(6)
Summary
526(1)
A PEAR and PECL Package Index
527(86)
Authentication
527(3)
Benchmarking
530(1)
Caching
530(1)
Configuration
531(1)
Console
531(2)
Database
533(9)
Date and Time
542(1)
Encryption
543(2)
File Formats
545(3)
File System
548(2)
Gtk Components
550(1)
HTML
550(11)
HTTP
561(2)
Images
563(3)
Internationalization
566(2)
Logging
568(1)
Mail
569(2)
Math
571(3)
Networking
574(10)
Numbers
584(1)
Payment
585(2)
PEAR
587(1)
PHP
588(6)
Processing
594(1)
Science
594(2)
Streams
596(1)
Structures
596(2)
System
598(1)
Text
599(1)
Tools and Utilities
600(3)
Web Services
603(1)
XML
604(9)
B phpDocumentor Format Reference
613(30)
Introduction
613(1)
Documentation Comments
613(2)
Tag Reference
615(17)
abstract
615(1)
access
616(1)
author
617(1)
category
618(1)
copyright
618(1)
deprecated
618(1)
example
619(1)
filesource
620(1)
final
620(1)
global
621(1)
ignore
622(1)
inheritdoc (inline)
622(1)
internal, internal (inline)
622(1)
licence
623(1)
link
623(1)
link (inline)
623(1)
name
624(1)
package
624(2)
param
626(1)
return
627(1)
see
627(1)
since
628(1)
static
628(1)
staticvar
629(1)
subpackage
629(1)
todo
630(1)
uses
630(1)
var
631(1)
version
631(1)
Tag Table
632(1)
Using the phpDocumentor Tool
633(10)
C Zend Studio Quick Start Guide
643(12)
Version 3.5.x
643(1)
About the Zend Studio Client Quick Start Guide
643(1)
About Zend
643(1)
Zend Studio Client: Overview
644(3)
Studio Components
644(1)
Client Server Configuration
645(1)
Installation and Registration
645(2)
Editing a File
647(1)
Editing a File
647(1)
Working with Projects
648(1)
Advantages of Working with Projects
648(1)
How to Create a Project
648(1)
Running the Debugger
648(2)
Internal Debugger
649(1)
Remote Debugger
649(1)
Debug URL
650(1)
Configure Studio Server for Remote Debugger and Profiling
650(1)
Running the Profiler
651(1)
Product Support
652(1)
Getting Support
653(1)
Main Features
653(2)
Index 655

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

Preface Preface "The best security against revolution is in constant correction of abuses and the introduction of needed improvements. It is the neglect of timely repair that makes rebuilding necessary."--Richard Whately In the Beginning It was eight years ago, when Rasmus Lerdorf first started developing PHP/FI. He could not have imagined that his creation would eventually lead to the development of PHP as we know it today, which is being used by millions of people. The first version of "PHP/FI," called Personal Homepage Tools/Form Interpreter,was a collection of Perl scripts in 1995.1One of the basic features was a Perl-like language for handling form submissions, but it lacked many common useful language features, such as loops. PHP/FI 2 A rewrite came with PHP/FI 22in 1997, but at that time the development was almost solely handled by Rasmus. After its release in November of that year, Andi Gutmans and Zeev Suraski bumped into PHP/FI while looking for a language to develop an e-commerce solution as a university project. They discovered that PHP/FI was not quite as powerful as it seemed, and its language was lacking many common features. One of the most interesting aspects included the way loops were implemented. The hand-crafted lexical scanner would go through the script and when it hit the while keyword it would remember its position in the file. At the end of the loop, the file pointer sought back to the saved position, and the whole loop was reread and re-executed. PHP 3 Zeev and Andi decided to completely rewrite the scripting language. They then teamed up with Rasmus to release PHP 3, and along also came a new name: PHP: Hypertext Preprocessor, to emphasize that PHP was a different product and not only suitable for personal use. Zeev and Andi had also designed and implemented a new extension API. This new API made it possible to easily support additional extensions for performing tasks such as accessing databases, spell checkers and other technologies, which attracted many developers who were not part of the "core" group to join and contribute to the PHP project. At the time of PHP 3's release3in June 1998, the estimated PHP installed base consisted of about 50,000 domains. PHP 3 sparked the beginning of PHP's real breakthrough, and was the first version to have an installed base of more than one million domains. PHP 4 In late 1998, Zeev and Andi looked back at their work in PHP 3 and felt they could have written the scripting language even better, so they started yet another rewrite. While PHP 3 still continuously parsed the scripts while executing them, PHP 4 came with a new paradigm of "compile first, execute later." The compilation step does not compile PHP scripts into machine code; it instead compiles them into byte code, which is then executed by the Zend Engine(Zend stands for Zeev & A ndi), the new heart of PHP 4. Because of this new way of executing scripts, the performance of PHP 4 was much better than that of PHP 3, with only a small amount of backward compatibility breakage4. Among other improvements was an improved extension API for better run-time performance, a web server abstraction layer allowing PHP 4 to run on most popular web servers, and lots more. PHP 4 was officially released on May 22, 2002, and today its installed base has surpassed 15 million domains. In PHP 3, the minor version number (the middle digit) was never used, and all versions were numbered as 3.0.x. This changed in PHP 4, and the minor version number was used to denote important changes in the language. The first important change came in PHP 4.1.0,5which introduced superglobalssuch as and . Superglobals can be accessed from within functions without having to use the keyword. This feature was added in order to allow the register_globals INI option to be turned off. register_globals is a feature in PHP which automatically converts input variables like "?foo=bar" inhttp://php.net/?foo=barto a PHP variable called $foo. Because many people do not check input variables properly, many applications had security holes, which made it quite easy to circumvent security and authentication code. With the new superglobals in place, on April 22, 2002, PHP 4.2.0 was released with the register_globals turned off by default. PHP 4.3.0, the last significant PHP 4 version, was released on December 27, 2002. This version introduced the Command Line Interface(CLI), a revamped file and network I/O layer (called streams), and a bundled GD library. Although most of those additions have no real effect on end users, the major version was bumped due to the major changes in PHP's core. PHP 5 Soon after, the demand for more common object-oriented features increased immensely, and Andi came up with the idea of rewriting the objected-oriented part of the Zend Engine. Zeev and Andi wrote the "Zend Engine II: Feature Overview and Design" document6and jumpstarted heated discussions about PHP's future. Although the basic language has stayed the same, many features were added, dropped, and changed by the time PHP 5 matured. For example, namespaces and multiple inheritance, which were mentioned in the original document, never made it into PHP 5. Multiple inheritance was dropped in favor of interfaces, and namespaces were dropped completely. You can find a full list of new features in Chapter, "What Is New in PHP 5?" PHP 5 is expected to maintain and even increase PHP's leadership in the web development market. Not only does it revolutionizes PHP's object-oriented support but it also contains many new features which make it the ultimate web development platform. The rewritten XML functionality in PHP 5 puts it on par with other web technologies in some areas and overtakes them in others, especially due to the new SimpleXML extension which makes it ridiculously easy to manipulate XML documents. In addition, the new SOAP, MySQLi, and variety of other extensions are significant milestones in PHP's support for additional technologies. Audience This book is an introduction to the advanced features new to PHP 5. It is written for PHP programmers who are making the move to PHP 5. Although Chapter 2, "PHP 5 Basic Language," contains an introduction to PHP 5 syntax, it is meant as a refresher for PHP programmers and not as a tutorial for new programmers. However, web developers with experience programming other high-level languages may indeed find that this tutorial is all they need in order to begin working effectively with PHP 5. Chapter Overview Chapter 1, "What Is New in PHP 5?" discusses the new features in PHP 5. Most of these new features deal with new object-oriented features, including small examples for each feature. It also gives an overview of the new extensions in PHP 5. Most of the topics mentioned in this chapter are explained in more detail in later chapters. Chapter 2, "PHP 5 Basic Language," introduces the PHP syntax to those readers not familiar with PHP. All basic language constructs and variable types are explained along with simple examples to give the reader the necessary building blocks to build real scripts. Chapter 3, "PHP 5 OO Language," continues exploring PHP 5's syntax, focusing on its object-oriented functionality. This chapter covers basics, such as properties and methods, and progresses to more complicated subjects, such as polymorphism, interfaces, exceptions, and lots more. Using the previous chapter as a foundation, Chapter 4, "PHP 5 Advanced OOP and Design Patterns," covers some of the most advanced features of PHP 5's object model. After learning these features, including four commonly used design patterns an

Rewards Program