PHP Objects, Patterns, and Practice(Apress,2016)

所需积分/C币:9 2016-12-23 17:00:56 7.54MB PDF
收藏 收藏
举报

The 5th edition of this popular book has been fully updated for PHP 7, including replacing the PEAR package manager with Composer, and new material on Vagrant and PHP standards. It provides a solid grounding in PHP’s support for objects, it builds on this foundation to instill core principles of sof
PHP Objects, Patterns, and practice Matt zandstra Liverpool, Merseyside United Kingdom ISBN-13(pbk):978-1-4842-1995-9 ISBN-13(electronic): 978-1-4842-1996-6 DOI10.1007/978-1-4842-1996-6 Library of Congress Control Number: 2016961297 Copyright o 2016 by Matt Zandstra This work is subject to copyright All rights are reserved by the publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now Known or hereafter developed Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights While the advice and information in this book are believed to be true and accurate at the date of publication neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein Managing director: Welmoed spahr Acquisitions Editor: Louise Corrigan Technical Reviewer: Paul Tregoing Editorial Board: Steve Anglin, Pramila Balan, Laura Berendson, Aaron Black, Louise Corrigan Jonathan Gennick, Todd Green, Robert Hutchinson, Celestin Suresh John, Nikhil Karkal James Markham, Susan McDermott, Matthew Moodie, Natalie Pao, Gwenan Spearing Coordinating Editor: Nancy Chen Copy Editor: Patrick Meador Compositor: SPi Global Indexer: SPi Global Artist: SPi Global, image courtesy of Freepik Distributed to the book trade worldwide by Springer Science+Business Media New York 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax(201)348-4505 e-mailorders-ny@springer-sbm.com,orvisitwww.springercomApressmediaLlcisaCalifornia LLC and the sole member (owner )is Springer Science Business Media Finance Inc(SSBM Finance Inc) SSBM Finance inc is a delaware corporation Forinformationontranslationspleasee-mailrights@apress.comorvisitwww.apress.com Apress and friends of ed books may be purchased in bulk for academic, corporate, or promotional use Book versions and licenses are also available for most titles. For more information, reference our Special BulksAles-ebookLicensingwebpageatwww.apress.com/bulk-sales Any source code or other supplementary materials referenced by the author in this text are available to readersatwww.apress.comFordetailedinformationabouthowtolocateyourbookssourcecodegoto Www.apress. com/source-code/. Readers can also access source code at Springerlink in the Supplementary Material section for each chapter Printed on acid-free paper www.allitebooks.com For Louise, who is the whole point. www.allitebooks.com Contents at a glance About the author About the tecnical reviewer Acknowledgments XXV Introduction xxvii Part I: Objects Chapter 1: PHP: Design and Management.maar ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 139 Chapter 2: PHP and objects.ar ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Chapter 3: Object Basics a 15 Chapter 4: Advanced Features stain 47 Chapter 5: Object Tools ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 99 Chapter 6: Objects and Design mm mmma 133 Part l: patterns ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 155 Chapter 7: What Are Design Patterns? Why Use Them? a157 Chapter 8: Some Pattern Principles 165 Chapter9: Generating0 bjects,,,,,,,,,…,,,…,,…,,,…179 Chapter 10: Patterns for Flexible Object Programming mmmmmmmmm 211 Chapter 11: Performing and Representing Tasks B R mImaiaain 235 Chapter 12: Enterprise Patterns 277 Chapter 13: Database patterns ammaammmanmmmaammmanmaammmnnm 327 www.allitebooks.com CONTENTS AT A GLANCE Part: Practice…375 Chapter 14: Good (and Bad) practice amman 377 Chapter 15: PHP Standards 385 Chapter 16: PHP Using and creating Components with Composer mammin 399 Chapter 17: Version Control with Git Chapter 18: Testing with PHPUnit 435 Chapter 19: Automated Build with Phing 465 Chapter 20: Vagrant. ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 487 Chapter21: Continuous Integration.,…,,,,…,,m,m,…,m,,,m…,,…,497 Chapter 22: Objects Patterns, Practice RBBBBBBBRRRRRRRBRBRIRIa 525 Chapter 23: Appendix A: Bibliography ma mmmamammma 535 Chapter 24: Appendix B: A simple Parser 539 Index 565 www.allitebooks.com Contents About the author…xi About the tecnical reviewer Acknowledgments Introduction mmmxxvii Part:0 bjects,… Chapter 1: PHP: Design and Management ■■■■■■■口■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■■■■■■■口■■■■■■■ The problem PHP and other Languages About this book 133466 Objects Patterns…6 Practice What's new in the fifth edition Summary 8 Chapter 2: PHP and objects ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ The Accidental Success of PHP objects In the beginning:PHP/F|………,… 9999 Syntactic Sugar: PHP 3 PHP 4 and the quiet Revolution. Change Embraced: PHP 5 PHP 7: Closing the Gap .................................12 Advocacy and Agnosticism The object Debate nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnDDnnDDDnnDDD 12 Summary.......e... nnnnnnnnnnnnnnnnnnnnnD 13 www.allitebooks.com CONTENTS Chapter 3: Object Basics RR RRRRRERO 15 Classes and objects 15 A First class mm..mmm., 15 A First Object (or TwO 16 Setting Properties in a class 17 Working with Methods 19 Creating a Constructor Method........... 21 Arguments and Types 22 Primitive Types…...,,.,.,.,.,.,.,.,.,.,., 22 Taking the Hint: object types..n 26 Inheritance 30 The inheritance problem 30 Working with Inheritance 35 Public, Private, and Protected: Managing Access to Your Classes Summary… 46 Chapter 4: Advanced Features 47 Static Methods and properties. Constant Properties 51 Abstract classes 51 Interfaces 53 Traits 55 A Problem for traits to solve mw 56 Defining and Using a Trait....………………57 Using More than0 ne trait.…........,.,...,…,………58 Combining traits and Interfaces..ed Managing method Name conflicts with insteadof . Aliasing overridden trait methods……,,,.,.,,.,,… …61 Using static methods in traits......................................61 www.allitebooks.com CONTENTS Accessing Host Class Properties Defining abstract methods in traits. Changing Access Rights to Trait Methods ….64 Late Static Bindings: The static Keyword 65 Handling errors 68 Exceptions Final classes and methods The internal error class Working with Interceptors nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnDnnDDnnDnDDnnDDDnDDDnnDDDnnDD Defining Destructor Methods. Copying objects with_clone …87 Defining String values for Your objects 90 Callbacks, Anonymous Functions, and Closures Anonymous classes灬 95 Summary… 97 Chapter 5: Object Tools.mmamammaaanamamamamaammnmm 99 PHP and packages 99 PHP Packages and namespaces.samms Autoload 日面日日面日画面日日自面日面日日面B面日面日日面日日面日日面日面日日面日画面日日自面日面日面面日面日面面日面面日面日日面面日面日日面面日面面日面日面面日面面目面日面面日面面日面日面面日面面日面面日 108 The class and object Functions 112 Looking for classes......... 量面a面B自面日面面B日面日面日日面面日B面日面面面面日面面B面面面日面面正日面B面日日面面日B 113 earning About an object or class 113 Getting a Fully Qualified String Reference to a Class. Learning about Methods .......................................................115 Learning about properties Learning about Inheritance . Method| vocation,…… 118 www.allitebooks.com CONTENTS The reflection apl ,119 Getting Started 120 Time to ro‖ up Your Sleeves∴ 120 Examining a class 122 EXamining Methods 124 EXamining Method Arguments 126 Using the reflection APl 127 Summary….,,… ……131 Chapter 6: Objects and design u33 Defining Code Design 133 0 bject- Oriented and Procedural Programming…,……134 Responsibility… 138 Cohesion 138 coupling . 139 Orthogonality ■B日日日日日日日日日日日日日日日日日日国日日日日日日日日国面日面国面日面面日面面面面面国B面面国B面面国B面面 …139 Choosing Your Classes 139 Polymorphism 140 Encapsulation 142 Forget How to Do|t.… 142 Four Signposts 143 Code duplication The class who knew too much 143 The jack of all trades Conditional statements mmmmmmmm 144 The UMl Class diagrams......................,,………144 Sequence Diagrams…....................151 153 www.allitebooks.com

...展开详情
试读 127P PHP Objects, Patterns, and Practice(Apress,2016)
立即下载 低至0.43元/次 身份认证VIP会员低至7折
    抢沙发
    一个资源只可评论一次,评论内容不能少于5个字
    关注 私信 TA的资源
    上传资源赚积分,得勋章
    最新推荐
    PHP Objects, Patterns, and Practice(Apress,2016) 9积分/C币 立即下载
    1/127
    PHP Objects, Patterns, and Practice(Apress,2016)第1页
    PHP Objects, Patterns, and Practice(Apress,2016)第2页
    PHP Objects, Patterns, and Practice(Apress,2016)第3页
    PHP Objects, Patterns, and Practice(Apress,2016)第4页
    PHP Objects, Patterns, and Practice(Apress,2016)第5页
    PHP Objects, Patterns, and Practice(Apress,2016)第6页
    PHP Objects, Patterns, and Practice(Apress,2016)第7页
    PHP Objects, Patterns, and Practice(Apress,2016)第8页
    PHP Objects, Patterns, and Practice(Apress,2016)第9页
    PHP Objects, Patterns, and Practice(Apress,2016)第10页
    PHP Objects, Patterns, and Practice(Apress,2016)第11页
    PHP Objects, Patterns, and Practice(Apress,2016)第12页
    PHP Objects, Patterns, and Practice(Apress,2016)第13页
    PHP Objects, Patterns, and Practice(Apress,2016)第14页
    PHP Objects, Patterns, and Practice(Apress,2016)第15页
    PHP Objects, Patterns, and Practice(Apress,2016)第16页
    PHP Objects, Patterns, and Practice(Apress,2016)第17页
    PHP Objects, Patterns, and Practice(Apress,2016)第18页
    PHP Objects, Patterns, and Practice(Apress,2016)第19页
    PHP Objects, Patterns, and Practice(Apress,2016)第20页

    试读已结束,剩余107页未读...

    9积分/C币 立即下载 >