Expert PHP 5 Tools Packt Open Source Project Royalties

Total Page:16

File Type:pdf, Size:1020Kb

Expert PHP 5 Tools Packt Open Source Project Royalties Expert PHP 5 Tools Proven enterprise development tools and best practices for designing, coding, testing, and deploying PHP applications Dirk Merkel BIRMINGHAM - MUMBAI Download from Wow! eBook www.WoweBook.com Expert PHP 5 Tools Copyright © 2010 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: April 2010 Production Reference: 1240310 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847198-38-9 www.packtpub.com Cover Image by Karl Swedberg ([email protected]) Download from Wow! eBook www.WoweBook.com Credits Author Editorial Team Leader Dirk Merkel Gagandeep Singh Reviewers Project Team Leader Andrew J. Peterson Lata Basantani Deepak Vohra Project Coordinator Acquisition Editor Joel Goveya Douglas Paterson Proofreader Development Editor Claire Cresswell-Lane Ved Prakash Jha Graphics Technical Editor Geetanjali Sawant Neha Damle Production Coordinator Indexer Shantanu Zagade Monica Ajmera Melwyn D'sa Cover Work Melwyn D'sa Download from Wow! eBook www.WoweBook.com About the Author Dirk Merkel has been developing software in a variety of programming languages for many years, including PHP, Java, Perl, and Ruby. His focus has been on web-related technologies and he has over 10 years experience coding in PHP. He has experience covering the whole software development cycle and has been managing several teams of developers working on large-scale projects. He has been working as a professional consultant through his company Waferthin Web Works LLC (http://www.waferthin.com) and can be reached at [email protected]. He is also the Chief Technology Officer at VivanTech Inc., a San Diego based provider of IT solutions. He has written several articles on software development and security. Expert PHP 5 Tools is his first book. He lives in San Diego with his lovely wife and two wonderful daughters. I would like to thank my family (near and far)—especially my parents and sisters, my lovely wife, Rania, and my two awesome daughters, Nadia and Yasmin. Download from Wow! eBook www.WoweBook.com About the Reviewers Andrew J. Peterson lives with his wife and three daughters in San Francisco, California. He has 20 years experience building and managing software systems for consumers, enterprises, start-ups, and non-profits. He brings expertise in the full life-cycle of software development, engineering, methodologies, architecture, and usability. He has diverse experience in the industry. In the consumer space, he led a team in the creation of the top-selling SoundEdit 16. He served numerous roles producing enterprise software, for the leading supplier of software solutions for container terminals, shipping ports and lines, and distribution centers. Over the past ten years, he transferred this experience to web-based software. He has built a variety of web applications, including non-profit, social networking, social search, pharmaceuticals and social ecommerce. He has build successful projects in a variety of languages, including Java, Ruby, C++, Ruby and Perl. In the primal days of the Web, he wrote a manual helping users connect their Macintosh to the Web. More recently, he reviewed PHP and Scriptaculous Web Application Interfaces for Packt Publishing. I'd like to thank my wife for the bliss she brings. Deepak Vohra is a consultant and a principal member of the NuBean.com software company. Deepak is a Sun Certified Java Programmer and Web Component Developer, and has worked in the fields of XML and Java programming and J2EE for over five years. Deepak is the co-author of the Apress book Pro XML Development with Java Technology and was the technical reviewer for the O'Reilly book WebLogic: The Definitive Guide. Deepak was also the technical reviewer for the Course Technology PTR book Ruby Programming for the Absolute Beginner, and the technical editor for the Manning Publications book Prototype and Scriptaculous in Action. Deepak is also the author of the Packt Publishing books JDBC 4.0 and Oracle JDeveloper for J2EE Development and Processing XML Documents with Oracle JDeveloper 11g. Download from Wow! eBook www.WoweBook.com Download from Wow! eBook www.WoweBook.com Table of Contents Preface 1 Chapter 1: Coding Style and Standards 5 Coding standard considerations 5 Pros 6 Cons 7 A PHP coding standard 7 Formatting 8 PHP tags 8 Indenting 8 Line length 8 Line endings 8 Spacing 9 Statements 9 Strings 10 Arrays 11 Control structures 12 Class and method definitions 14 Naming conventions 14 Class names 14 Property and variable names 16 Constant names 17 Method and function names 17 Methodology 19 Type hinting 19 Separating object creation from initialization 19 Class files 20 Class names and directory structures 20 Visibility and access 21 Including source files 22 Comments 23 Inline documentation 23 Download from Wow! eBook www.WoweBook.com Table of Contents Coding standard adherence and verification 25 PHP_CodeSniffer for automated checking 25 Installing PHP_CodeSniffer 25 Basic usage 27 Slightly advanced usage 27 Validating against your own coding standard 29 Summary 38 Chapter 2: Documentation with phpDocumentor 39 Code-level documentation 40 Levels of detail 41 Introducing phpDocumentor 42 Installing phpDocumentor 42 DocBlocks 44 Short and long descriptions 44 Tags 44 DocBlock templates 45 Tutorials 46 Naming conventions and how to reference tutorials 47 DocBook syntax 48 Documenting a project 49 Documentation without DocBlocks 54 Documentation with DocBlocks 57 phpDocumentor options 67 Command line reference 67 Config files 69 Browser-based interface 70 Tag reference 71 Standard tags 71 Inline tags 83 PHP4 elements 91 Custom tags 92 Summary 92 Chapter 3: The Eclipse Integrated Development Environment 93 Why Eclipse? 94 Introducing PDT 96 Installing Eclipse 96 Requirements 96 Choosing a package 98 Adding the PDT plugin 99 Basic Eclipse concepts 100 Workspace 101 Views 102 Perspectives 104 [ ii ] Download from Wow! eBook www.WoweBook.com Table of Contents A PDT sample project 106 PDT features 109 Editor 109 Syntax highlighting 109 Code assist 110 Code folding 110 Mark occurrences 111 Override indicators 112 Type, method, and resource navigation 112 Inspection 114 Projects and files 114 PHP explorer 114 Type hierarchy 115 Debugging 115 PDT preferences 119 Appearance 119 Code style 119 Debug 120 Editor 121 New project layout 123 PHP executables 124 PHP interpreter 124 PHP manual 124 PHP servers 125 Templates 125 Other features 126 PHP function reference 126 Eclipse plugins 127 Zend Studio for Eclipse 129 Support 131 Refactoring 131 Code generation 131 PHPUnit testing 132 PhpDocumentor support 133 Zend Framework integration 133 Zend server integration 133 Summary 134 Chapter 4: Source Code and Version Control 135 Common use cases 136 A brief history of source code control 136 CVS 140 Introducing Subversion 142 Client installation 142 Server configuration 143 [ iii ] Download from Wow! eBook www.WoweBook.com Table of Contents Apache with mod_dav_svn 143 Subversion concepts 143 Repository 144 Tags 144 Trunk 144 Branches 145 Working (Local) copy 145 Merging 146 Revisions and versions 146 Updating 146 Comparing 146 History/Log 147 Annotating code 147 Reverting 148 Committing 148 Subversion command reference 148 svn 148 svnadmin 157 svnlook 158 svnserve 158 svndumpfilter 158 svnversion 158 Creating a Subversion project 159 Basic version control workflow 168 A closer look at the repository 172 Data store 172 Layout 173 Branching and merging 174 What is a branch? 175 Why branch? 175 How to branch? 176 Maintaining and merging a branch 177 Branching workflow 180 UI clients 182 Eclipse plug-ins 182 TortoiseSVN 185 WebSVN 185 Subversion conventions and best practices 189 Customizing Subversion 190 Hooks 190 Notifying developers of commits with a post-commit hook 194 Summary 195 [ iv ] Download from Wow! eBook www.WoweBook.com Table of Contents Chapter 5: Debugging 197 First line of defense: syntax check 197 Logging 199 Configuration options 200 Customizing and controlling config options: PhpIni 202 PhpIni example 208 Outputting debug information 209 Functions 209 echo(string $arg1 [, string $... ] / print(string $arg) 210 var_dump(mixed $expression [, mixed $expression [, $... ]]) and print_r(mixed $expression [, bool $return= false ]) 210 highlight_string(string str [, bool return]) and highlight_file(string filename [, bool return]) 212 get_class([object object]) 212 get_object_vars(object object) 212 get_class_methods(mixed class_name) 212 get_class_vars(string class_name) 212 debug_backtrace() 213 debug_print_backtrace() 213 exit([string status]) or exit (int status) 213 Magic constants 213 Writing our own debugging class 214 Functional
Recommended publications
  • Documenting Your PHP Code with Phpdoc and Docbook XML -.. Phpbee
    Documenting your PHP code with PHPDoc and DocBook XML Gábor Hojtsy International PHP Conference 2002 November 3-6. 2002. Questions • Who used/know about PHPDoc? • JavaDoc? • DocBook XML? • XML at all? • Anyway who documents his/her code regularly using any format? Documenting your PHP code 2 About myself •Gábor Hojtsy • [email protected] • Student at Budapest University of Technology and Economics • PHP.net Webmasters Team • PHP Documentation Team [build system, XSLT rendering, CHM format, Hungarian translation] Documenting your PHP code 3 Session outline • Documentation types • Developer documentation • Possible formats • Inline documentation in PHP code • Standalone documentation in DocBook • Tools to handle the two and merge contents Documenting your PHP code 4 Documentation types • Software written in PHP • Plans, concepts, specification [UML] • As the software is stable – User’s documentation • Help buttons on web pages • Support pages, simple manuals – Developer’s documentation Documenting your PHP code 5 Developer’s documentation • General information – Authors, License, Links • Concepts explained – Reasons to develop this software – Technologies, libraries used • Implementation details – Meta information about classes, functions, variables, constants; with usage examples • Historical information – Previously supported API[s], future directions, todo Documenting your PHP code 6 Expected qualities • All information in one documentation • Easily accessible / modifiable – Industry- wide used format – Cross platform tools for viewing and
    [Show full text]
  • Zend Studio 5.5 for I5 /OS
    Zend StudioTM User Guide: Zend Studio 5.5 for i5 /OS By Zend Technologies, Inc. www.zend.com Zend Studio 5.5 for i5 /OS – User Guide Disclaimer The information in this document is subject to change without notice and does not represent a commitment on the part of Zend Technologies Ltd. No part of this manual may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or information storage and retrieval systems, for any purpose other than the purchaser’s personal use, without the written permission of Zend Technologies Ltd. All trademarks mentioned in this document, belong to their respective owners. © 1999-2007 Zend Technologies Ltd. All rights reserved. Zend Studio for i5/OS version 5.5 issued January 2007. Product Version: Zend Studio for i5/OS version 5.5 DN: ZSi5_OS-UG-270507-5.5-005 www.zend.com Page ii Zend Studio 5.5 for i5 /OS – User Guide Table of Contents Chapter 1 - Introduction.............................................................................................. 1 Zend Studio Components........................................................................................... 1 Zend Studio for i5/OS version 5.5 ............................................................................ 2 Zend Studio Workflow .............................................................................................. 3 New in this Version ................................................................................................. 4 Highlighted Features and Benefits
    [Show full text]
  • Facebook API Developers Guide
    Available as a PDF Electronic Book or Print On Demand Facebook API Developers Guide CHAPTER 1 Introducing the Facebook Platform . 1 CHAPTER 2 Getting Ready for Facebook Application Development . 9 CHAPTER 3 Learning Facebook Platform Fundamentals . 31 CHAPTER 4 Building a Facebook Application, Start to Finish. 71 CHAPTER 5 Going Further with Your Application . 129 137 PAGES Wayne Graham www.allitebooks.com www.allitebooks.com Facebook API Developers Guide WAYNE GRAHAM www.allitebooks.com Facebook API Developers Guide Copyright © 2008 by Wayne Graham All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13: 978-1-4302-0969-0 ISBN-10: 1-4302-0969-0 eISBN-13: 978-1-4302-0970-6 Printed and bound in the United States of America (POD) Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trade- marked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Ben Renow-Clarke Technical Reviewer: Mark Johnson Editorial Board: Clay Andres, Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Kevin Goff, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Senior Project Manager: Tracy Brown Collins Copy Editor: Kim Wimpsett Compositor: Richard Ables Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013.
    [Show full text]
  • E-LEARNING FRAMEWORKS 29 Introduction
    Voice Interactive Classroom, a service- oriented software architecture to enable cross-platform multi-channel access to Internet-based learning Víctor Manuel Álvarez García UNIVERSITY OF OVIEDO DEPARTMENT OF COMPUTER SCIENCE In Partial Fulfilment of the Requirements for the Degree of EUROPEAN DOCTOR OF PHILOSOPHY Universidad de Oviedo Voice Interactive Classroom, a service-oriented software architecture to enable cross-platform multi-channel access to Internet-based learning Víctor Álvarez García Depósito Legal: AS. 00480-2011 http://hdl.handle.net/10803/77825 ADVERTENCIA. El acceso a los contenidos de esta tesis doctoral y su utilización debe respetar los derechos de la persona autora. Puede ser utilizada para consulta o estudio personal, así como en actividades o materiales de investigación y docencia en los términos establecidos en el art. 32 del Texto Refundido de la Ley de Propiedad Intelectual (RDL 1/1996). Para otros usos se requiere la autorización previa y expresa de la persona autora. En cualquier caso, en la utilización de sus contenidos se deberá indicar de forma clara el nombre y apellidos de la persona autora y el título de la tesis doctoral. No se autoriza su reproducción u otras formas de explotación efectuadas con fines lucrativos ni su comunicación pública desde un sitio ajeno al servicio TDR. Tampoco se autoriza la presentación de su contenido en una ventana o marco ajeno a TDR (framing). Esta reserva de derechos afecta tanto al contenido de la tesis como a sus resúmenes e índices. WARNING. Access to the contents of this doctoral thesis and its use must respect the rights of the author.
    [Show full text]
  • Php Developer Best Practices
    PHP DEVELOPER BEST PRACTICES Mike Naberezny Matthew Weier O’Phinney Mike Naberezny • http://mikenaberezny.com • http://maintainable.com • http://ohloh.net/accounts/mnaberez ZendCon ‘06 ZendCon ‘07 Sep 15, 2008 | PHP Developer Best Practices Matthew Weier O’Phinney • http://weierophinney.net/matthew • http://framework.zend.com • http://ohloh.net/accounts/weierophinney ZendCon ‘06 ZendCon ‘07 Sep 15, 2008 | PHP Developer Best Practices About You • Web developer, using PHP • Is your code well organized and maintainable? • Are you using source control? • Is your software documented? • Do you have automated tests for your software? Sep 15, 2008 | PHP Developer Best Practices Agenda • Today we will present ideas and techniques that you can use to improve your development process. • Not every technique can apply to every project. • Start small; implement a few new practices at a time. • Find what works for your team and iterate on that. • Use this talk as a starting point to go off and learn more. Sep 15, 2008 | PHP Developer Best Practices Agenda • Source Control • Coding Standards • Testing • Documentation • Deployment • Q & A Sep 15, 2008 | PHP Developer Best Practices Source Control Sep 15, 2008 | PHP Developer Best Practices Source Control • Problems Source Control Solve • How do I know if somebody did something? • How do others know I did something? • How do I get my updates from others? • How do I push my updates out to others? • Do we have the old version? • What changed? Sep 15, 2008 | PHP Developer Best Practices Source Control • General
    [Show full text]