PHP objects, patterns, and practice

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Backed by a tireless development community, PHP has been a model of language evolution over its 10+ year history. Borne from a contract developer’s pet project, these days you’ll find PHP powering many of the world’s largest web sites, including Yahoo!, Digg, EA Games, and Lycos. PHP Objects, Patterns, and Practice, Second Edition shows you how to meld the power of PHP with the sound enterprise development techniques embraced by professional programmers. Going well beyond the basics of object–oriented development, you’ll learn about advanced topics such as working with static methods and properties, abstract classes, interfaces, design patterns, exception handling, and more. You’ll also be exposed to key tools such as PEAR, CVS, Phing, and phpDocumentor. What you’ll learn • Write solid, maintainable code by embracing object–oriented techniques and design patterns • Create detailed, versatile documentation using the powerful phpDocumentor automated documentation system • Gain new flexibility during the development process by managing your code within a CVS repository and using the Phing build system • Capitalize upon the quality code of others by using the PEAR package management solution Who this book is for PHP developers seeking to embrace sound development techniques such as object–orientation, design patterns, testing, and documentation.

Author(s): Matt Zandstra
Series: The expert’s voice in open source
Edition: 2
Publisher: Apress
Year: 2007

Language: English
Pages: 491

Prelims......Page 1
Contents at a Glance......Page 6
Contents......Page 9
About the Author......Page 19
About the Technical Reviewer......Page 20
Acknowledgments......Page 21
Introduction to the First Edition......Page 23
Introduction to the Second Edition......Page 25
The Problem......Page 29
PHP and Other Languages......Page 30
Objects......Page 32
Practice......Page 33
Summary......Page 34
Syntactic Sugar: PHP 3......Page 37
PHP 4 and the Quiet Revolution......Page 38
Into the Future: PHP 6......Page 40
Summary......Page 41
A First Class......Page 43
A First Object (or Two)......Page 44
Setting Properties in a Class......Page 45
Working with Methods......Page 48
Creating a Constructor Method......Page 49
Primitive Types......Page 51
Primitive Types Matter: An Example......Page 52
Taking the Hint: Object Types......Page 54
The Inheritance Problem......Page 56
Working with Inheritance......Page 60
Constructors and Inheritance......Page 62
Invoking an Overridden Method......Page 64
Public, Private, and Protected: Managing Access to Your Classes......Page 65
Accessor Methods......Page 66
The ShopProduct Classes......Page 67
Summary......Page 70
Static Methods and Properties......Page 71
Constant Properties......Page 74
Abstract Classes......Page 75
Interfaces......Page 77
Handling Errors......Page 79
Throwing an Exception......Page 81
Subclassing Exception......Page 82
Final Classes and Methods......Page 85
Working with Interceptors......Page 86
Defining Destructor Methods......Page 90
Copying Objects with __clone()......Page 92
Defining String Values for Your Objects......Page 94
Summary......Page 95
PHP and Packages......Page 97
PHP and Namespaces......Page 100
Include Paths......Page 102
Autoload......Page 103
The Class and Object Functions......Page 104
Looking for Classes......Page 105
Learning About Methods......Page 106
Learning About Inheritance......Page 108
Method Invocation......Page 109
Getting Started......Page 110
Time to Roll Up Your Sleeves......Page 111
Examining a Class......Page 113
Examining Methods......Page 114
Examining Method Arguments......Page 116
Using the Reflection API......Page 117
Summary......Page 121
Defining Code Design......Page 123
Object-Oriented and Procedural Programming......Page 124
Cohesion......Page 128
Choosing Your Classes......Page 129
Polymorphism......Page 130
Encapsulation......Page 132
Forget How to Do It......Page 133
Conditional Statements......Page 134
Representing Classes......Page 135
Attributes......Page 136
Describing Inheritance and Implementation......Page 137
Associations......Page 138
Aggregation and Composition......Page 140
Using Notes......Page 141
Sequence Diagrams......Page 142
Summary......Page 144
What Are Design Patterns?......Page 147
Name......Page 149
Consequences......Page 150
Why Use Design Patterns?......Page 151
Patterns Define a Vocabulary......Page 152
PHP and Design Patterns......Page 153
Summary......Page 154
The Pattern Revelation......Page 155
The Problem......Page 156
Using Composition......Page 159
The Problem......Page 161
Loosening Your Coupling......Page 162
Code to an Interface, Not to an Implementation......Page 163
The Concept That Varies......Page 164
The Patterns......Page 165
Summary......Page 166
Problems and Solutions in Generating Objects......Page 167
The Singleton Pattern......Page 171
Implementation......Page 172
Consequences......Page 174
The Problem......Page 175
Implementation......Page 177
The Problem......Page 180
Implementation......Page 182
Consequences......Page 185
The Problem......Page 186
Implementation......Page 187
But That’s Cheating!......Page 190
Summary......Page 191
Structuring Classes to Allow Flexible Objects......Page 193
The Problem......Page 194
Implementation......Page 196
Consequences......Page 200
The Decorator Pattern......Page 203
The Problem......Page 204
Implementation......Page 206
The Facade Pattern......Page 209
The Problem......Page 210
Implementation......Page 211
Summary......Page 212
The Problem......Page 213
Implementation......Page 215
Interpreter Issues......Page 222
The Problem......Page 223
Implementation......Page 224
The Observer Pattern......Page 228
Implementation......Page 230
The Problem......Page 235
Implementation......Page 237
Visitor Issues......Page 241
Implementation......Page 242
Summary......Page 247
The Patterns......Page 249
Applications and Layers......Page 250
The Problem......Page 253
Implementation......Page 255
Registry, Scope, and PHP......Page 257
Consequences......Page 262
The Presentation Layer......Page 263
Implementation......Page 264
Consequences......Page 273
Implementation......Page 274
The Problem......Page 285
Implementation......Page 286
Consequences......Page 289
The Problem......Page 290
Implementation......Page 291
Consequences......Page 292
The Problem......Page 293
Implementation......Page 294
Consequences......Page 297
Implementation......Page 298
Consequences......Page 300
Summary......Page 301
The Data Layer......Page 303
Implementation......Page 304
Handling Multiple Rows......Page 309
Consequences......Page 316
The Problem......Page 317
Implementation......Page 318
Consequences......Page 320
Implementation......Page 321
Lazy Load......Page 325
Implementation......Page 326
The Problem......Page 328
Implementation......Page 329
Consequences......Page 330
The Problem......Page 331
Implementation......Page 332
The Selection Factory and Update Factory Patterns......Page 337
Implementation......Page 338
What’s Left of Data Mapper Now?......Page 341
Summary......Page 344
Beyond Code......Page 347
Borrowing a Wheel......Page 348
Playing Nice......Page 349
Giving Your Code Wings......Page 350
Documentation......Page 351
Testing......Page 352
Summary......Page 353
An Introduction to PEAR......Page 355
What Is PEAR?......Page 356
Installing a Package with PEAR......Page 357
PEAR Channels......Page 358
Using a PEAR Package......Page 359
Handling PEAR Errors......Page 361
package.xml......Page 364
Package Elements......Page 365
The contents Element......Page 367
Dependencies......Page 369
Tweaking Installation with phprelease......Page 371
Setting Up Your Own Channel......Page 372
Summary......Page 378
Why Document?......Page 379
Installation......Page 380
Generating Documentation......Page 381
DocBlock Comments......Page 383
Documenting Classes......Page 384
Documenting Properties......Page 386
Documenting Methods......Page 388
Creating Links in Documentation......Page 390
Summary......Page 393
Why Use Version Control?......Page 395
Getting CVS......Page 396
Creating a Repository......Page 397
Configuring the Client......Page 398
Running CVS Across Multiple Machines......Page 399
Beginning a Project......Page 400
Updating and Committing......Page 402
Removing a File......Page 406
Adding Binary Files......Page 407
Removing Directories......Page 408
Tagging and Exporting a Release......Page 409
Retrieving a Project by Tag......Page 410
Branching a Project......Page 411
Summary......Page 415
Functional Tests and Unit Tests......Page 417
Testing by Hand......Page 418
Creating a Test Case......Page 420
Assertion Methods......Page 422
Testing Exceptions......Page 423
Running Test Suites......Page 424
Constraints......Page 427
Mocks and Stubs......Page 429
Tests Succeed When They Fail......Page 432
A Note of Caution......Page 435
Summary......Page 437
What Is Phing?......Page 439
Getting and Installing Phing......Page 440
Composing the Build Document......Page 441
Targets......Page 442
Properties......Page 444
FileSet......Page 450
PatternSet......Page 451
FilterChain......Page 452
Tasks......Page 454
Copy......Page 455
Input......Page 456
Summary......Page 458
Objects......Page 461
Decoupling......Page 462
Aesthetics......Page 463
Patterns Suggest Other Patterns......Page 464
Favor Composition over Inheritance......Page 465
Practice......Page 466
Documentation......Page 467
What I Missed......Page 468
Summary......Page 469
Books......Page 473
Sites......Page 474
The Scanner......Page 475
The Parser......Page 483
Index......Page 497