Tài liệu Zend PHP 5 Certification Study Guide - By Davey Shafik with Ben Ramsey docx

278 362 1
Tài liệu Zend PHP 5 Certification Study Guide - By Davey Shafik with Ben Ramsey docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

.571 7.50 x 9.25 7.50 x 9.25 php|architect’s ZEND PHP 5 Certification STUDY GUIDE Davey Shafik with Ben Ramsey US $32.99 Canada $42.99 UK (net) £19.99 From the publishers of Shelve under PHP/Web Development/Internet Programming php|architect’s Zend PHP 5 Certification Guide D. Shafik / B. Ramsey php|architect’s Zend PHP 5 Certification Study Guide Zend's new PHP 5 Certification Exam represent an excellent tool for professional PHP developers who want to distinguish themselves in their field. php|architect's Zend PHP 5 Certification Study Guide, edited and produced by the publishers of php|architect magazine, provides the most comprehensive and thorough preparation tool for developers who wish to take the exam. This book provides complete coverage of every topic that is part of the exam, including: ✔ PHP Basics ✔ Functions ✔ Arrays ✔ Strings and Patterns ✔ Web Programming ✔ Object Oriented Programming ✔ Database Programming ✔ Object-oriented Design ✔ XML and Web Services ✔ Security ✔ Streams and Network Programming ✔ Differences Between PHP 4 and 5 Written by PHP professionals and Zend Certified PHP 5 Engineers Davey Shafik and Ben Ramsey, and reviewed by core PHP developer Derick Rethans, this is the perfect book for every prospective Zend Certified PHP Engineer candidate! php|architect’s Zend PHP 5 Certification Study Guide by Davey Shafik with Ben Ramsey php|architect’s Zend PHP 5 Certification Guide Contents Copyright ©2006 David Shafik and Ben Ramsey – All Rights Reserved Book and cover layout, design and text Copyright ©2004-2006 Marco Tabini & Associates, Inc. – All Rights Reserved First Edition: October 2006 ISBN: 0-9738621-4-9 Produced in Canada Printed in the United States No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by means without the prior written permission of the publisher, excet in the case of brief quotations embedded in critical reviews or articles. Disclaimer Although every effort has been made in the preparation of this book to ensure the accuracy of the information contained therein, this book is provided “as-is” and the publisher, the author(s), their dis- tributors and retailers, as well as all affiliated, related or subsidiary parties take no responsibility for any inaccuracy and any and all damages caused, either directly or indirectly, by the use of such informa- tion. We have endeavoured to properly provide trademark information on all companies and products mentioned in the book by the appropriate use of capitals. However, we cannot guarantee the accuracy of such information. Marco Tabini & Associates, The MTA logo, php|architect, the php|architect logo, NanoBook and the NanoBook logo are trademarks or registered trademarks of Marco Tabini & Associates, Inc. Written by Davey Shafik Ben Ramsey Published by Marco Tabini & Associates, Inc. 28 Bombay Ave. Toronto, ON M3H 1B7 Canada (416) 630-6202 / (877) 630-6202 info@phparch.com / www.phparch.com Edited by Sean Coates Technical Reviewers Derick Rethans Paul Reinheimer Layout and Design Arbi Arzoumani Managing Editor Emanuela Corso Contents Foreword xv How To Use This Book xvii Chapter 1 — PHP Basics 3 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Source Files and PHP Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Newline Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Anatomy of a PHP Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Whitespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Code Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Language Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Numeric Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Booleans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Compound Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Other Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Converting Between Data Types . . . . . . . . . . . . . . . . . . . . . . . 11 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Variable Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Determining If a Variable Exists . . . . . . . . . . . . . . . . . . . . . . . . 14 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 vi ” CONTENTS Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 The String Concatenation Operator . . . . . . . . . . . . . . . . . . . . . 17 Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Referencing Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Other Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Operator Precedence and Associativity . . . . . . . . . . . . . . . . . . . 25 Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Conditional Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Iterative Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Breaking and Continuing . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Errors and Error Management . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Types of Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Error Reporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Handling Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Chapter 2 — Functions 37 Basic Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Returning Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Passing Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Variable-length Argument Lists . . . . . . . . . . . . . . . . . . . . . . . . 42 Passing Arguments by Reference . . . . . . . . . . . . . . . . . . . . . . . 43 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Chapter 3 — Arrays 47 Array Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Printing Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Enumerative vs. Associative . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Multi-dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Unravelling Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 CONTENTS ” vii Array Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Comparing Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Counting, Searching and Deleting Elements . . . . . . . . . . . . . . . . 53 Flipping and Reversing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Array Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 The Array Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 An Easier Way to Iterate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Passive Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Sorting Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Other Sorting Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 The Anti-Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Arrays as Stacks, Queues and Sets . . . . . . . . . . . . . . . . . . . . . . . . . 67 Set Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Chapter 4 — Strings And Patterns 73 String Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Variable Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 The Heredoc Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Escaping Literal Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Determining the Length of a String . . . . . . . . . . . . . . . . . . . . . . 76 Transforming a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Using Strings as Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Comparing, Searching and Replacing Strings . . . . . . . . . . . . . . . . . . . 78 Simple Searching Functionality . . . . . . . . . . . . . . . . . . . . . . . . 79 Matching Against a Mask . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Simple Search and Replace Operations . . . . . . . . . . . . . . . . . . . 81 Extracting Substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Formatting Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Formatting Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Formatting Currency Values . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Generic Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Parsing Formatted Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Perl-compatible Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . 89 viii ” CONTENTS Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Metacharacters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Sub-Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Matching and Extracting Strings . . . . . . . . . . . . . . . . . . . . . . . 92 Using PCRE to Replace Strings . . . . . . . . . . . . . . . . . . . . . . . . 94 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Chapter 5 — Web Programming 97 Anatomy of a Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Forms and URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 GET and URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Using POST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 When You Don’t Know How Data Is Sent . . . . . . . . . . . . . . . . . . 101 Managing File Uploads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 GET or POST? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 HTTP Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Compression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Chapter 6 — Object Oriented Programming in PHP 113 OOP Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Declaring a Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Instantiating an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Class Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Class Methods and Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Visibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Declaring and Accessing Properties . . . . . . . . . . . . . . . . . . . . . 122 Constants, Static Methods and Properties . . . . . . . . . . . . . . . . . . . . . 123 CONTENTS ” ix Class Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Interfaces & Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Determining An Object’s Class . . . . . . . . . . . . . . . . . . . . . . . . 128 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 The Basic Exception Class . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Throwing Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Lazy Loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Reflection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Chapter 7 — Database Programming 141 An Introduction to Relational Databases and SQL . . . . . . . . . . . . . . . . 141 Indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 SQL Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Creating Databases and Tables . . . . . . . . . . . . . . . . . . . . . . . . 145 Creating Indices and Relationships . . . . . . . . . . . . . . . . . . . . . 146 Dropping Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Adding and Manipulating Data . . . . . . . . . . . . . . . . . . . . . . . . 148 Removing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Retrieving Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 SQL Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Outer Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Advanced Database Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Prepared Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Chapter 8 — Elements of Object-oriented Design 157 Design Pattern Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 The Singleton Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 The Factory Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 The Registry Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 The Model-View-Controller Pattern . . . . . . . . . . . . . . . . . . . . . 161 . prospective Zend Certified PHP Engineer candidate! php| architect’s Zend PHP 5 Certification Study Guide by Davey Shafik with Ben Ramsey php| architect’s Zend PHP 5. .57 1 7 .50 x 9. 25 7 .50 x 9. 25 php| architect’s ZEND PHP 5 Certification STUDY GUIDE Davey Shafik with Ben Ramsey US $32.99 Canada

Ngày đăng: 15/12/2013, 12:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan