php zend framework

Download PHP Zend Framework

Post on 22-Mar-2016

225 views

Category:

Documents

3 download

Embed Size (px)

DESCRIPTION

end Framework

TRANSCRIPT

  • .5717.50 x 9.25 7.50 x 9.25

    php|architects

    ZEND PHP 5 Certification STUDY GUIDE

    Davey Shafik with Ben Ramsey

    US $32.99Canada $42.99UK (net) 19.99 From the publishers of

    Shelve under PHP/Web Development/Internet Programming

    php

    |arc

    hite

    cts

    Zen

    d P

    HP

    5 C

    erti

    fica

    tion

    Gui

    de

    D.

    Shaf

    ik /

    B. R

    amse

    y

    php|architectsZend PHP 5 CertificationStudy GuideZend'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 andBen Ramsey, and reviewed by core PHP developer Derick Rethans, this is the perfectbook for every prospective Zend Certified PHP Engineer candidate!

  • php|architects

    Zend PHP 5 CertificationStudy Guide

    by Davey Shafikwith Ben Ramsey

  • php|architects Zend PHP 5 Certification GuideContents Copyright 2006 David Shafik and Ben Ramsey All Rights ReservedBook and cover layout, design and text Copyright 2004-2006 Marco Tabini & Associates, Inc. All Rights Reserved

    First Edition: October 2006ISBN: 0-9738621-4-9Produced in CanadaPrinted in the United States

    No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form orby means without the prior written permission of the publisher, excet in the case of brief quotationsembedded in critical reviews or articles.

    DisclaimerAlthough every effort has been made in the preparation of this book to ensure the accuracy of theinformation 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 anyinaccuracy 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 productsmentioned in the book by the appropriate use of capitals. However, we cannot guarantee the accuracyof such information.

    Marco Tabini & Associates, The MTA logo, php|architect, the php|architect logo, NanoBook and theNanoBook logo are trademarks or registered trademarks of Marco Tabini & Associates, Inc.

    Written by Davey ShafikBen Ramsey

    Published by Marco Tabini & Associates, Inc.28 Bombay Ave.Toronto, ONM3H 1B7Canada

    (416) 630-6202 / (877) 630-6202info@phparch.com / www.phparch.com

    Edited by Sean Coates

    Technical Reviewers Derick RethansPaul Reinheimer

    Layout and Design Arbi Arzoumani

    Managing Editor Emanuela Corso

  • Contents

    Foreword xv

    How ToUse This Book xvii

    Chapter 1PHP Basics 3Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Source Files and PHP Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Newline Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Anatomy of a PHP Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Whitespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Code Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Language Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Numeric Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Booleans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Compound Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Other Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Converting Between Data Types . . . . . . . . . . . . . . . . . . . . . . . 11

    Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Variable Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Determining If a Variable Exists . . . . . . . . . . . . . . . . . . . . . . . . 14

    Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

  • vi CONTENTS

    Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16The String Concatenation Operator . . . . . . . . . . . . . . . . . . . . . 17Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Referencing Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Other Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Operator Precedence and Associativity . . . . . . . . . . . . . . . . . . . 25

    Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Conditional Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Iterative Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Breaking and Continuing . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    Errors and Error Management . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Types of Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Error Reporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Handling Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

    Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

    Chapter 2 Functions 37Basic Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Returning Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

    Passing Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Variable-length Argument Lists . . . . . . . . . . . . . . . . . . . . . . . . 42Passing Arguments by Reference . . . . . . . . . . . . . . . . . . . . . . . 43

    Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

    Chapter 3Arrays 47Array Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

    Printing Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48Enumerative vs. Associative . . . . . . . . . . . . . . . . . . . . . . . . . . 49Multi-dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Unravelling Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

  • CONTENTS vii

    Array Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Comparing Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Counting, Searching and Deleting Elements . . . . . . . . . . . . . . . . 53Flipping and Reversing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

    Array Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56The Array Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56An Easier Way to Iterate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58Passive Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

    Sorting Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61Other Sorting Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63The Anti-Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

    Arrays as Stacks, Queues and Sets . . . . . . . . . . . . . . . . . . . . . . . . . 67Set Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

    Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

    Chapter 4 Strings And Patterns 73String Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

    Variable Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74The Heredoc Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75Escaping Literal Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75Determining the Length of a String . . . . . . . . . . . . . . . . . . . . . . 76Transforming a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Using Strings as Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

    Comparing, Searching and Replacing Strings . . . . . . . . . . . . . . . . . . . 78Simple Searching Functionality . . . . . . . . . . . . . . . . . . . . . . . . 79Matching Against a Mask . . . . . . . . . . . . . . . . . . .