■ INDEX
502
naming collisions, 71, 74
nested namespaces, declaring, 73
PHP 5.3 and, 14, 71
phpDocumentor and, 353
relative namespaces, 74
require_once(), 76
switching to global space within a file, 76
unqualified name, 73
use keyword, 74
using a domain name as a namespace, 73
using braces with the namespace keyword,
75
using the as clause with use, 75
NastyBoss class, 146–147
new operator, 16, 21
newInstance(), 96
newSelection(), 310
newUpdate(), 309–310
next(), 477
nextToken(), 472–473, 477
Nock, Clifton, 298, 311
notes element, 336
Notifier class, 140
notify(), 204–205
notifyAccess(), 282, 298
notifyError(), 333
notifyPasswordFailure(), 389
null, using in hinted arguments, 27
■ O
object lifelines, 117
object types, 25
object-oriented design
abstract classes, 45
Abstract Factory pattern, 157
abstract types as enabling polymorphism,
146
addEmployee(), 147
addParam(), 102
aesthetics of, 455
anonymous functions, 66, 68
assigning and passing objects by reference,
63
automated build, 459
call_user_func(), 67
callbacks, 66
centralizing common classes used in
multiple projects, 455
class switching, 106
code duplication, 109, 454
code smells, 109
coding to an interface, 141, 457
cohesion, definition of, 104
comparing to procedural programming,
100, 103
Conf class, code listing, 51
constant properties, 44
Continuous Integration (CI), 460
controller, 454
copying objects with __clone(), 63
coupling in, 104
create_function(), 67–68
declaring a class or method final, 57
decoupling, definition of, 454
defining string values for objects, 65
defining the boundaries of classes, 105
delegating object instantiation, 147
describing a class’s responsibility, 105
designing child classes to provide
specialized functionality, 132
destructor methods, 62
devising strategies for object generation,
145, 147
DomainObject class, 49
Employee class, 146, 148
encapsulating the concept that varies, 458
encapsulation, 107–108
Factory Method pattern, 152
factory, definition of, 44, 148
favoring composition over inheritance, 132
final keyword, 57
focusing on the metasystem, 458
Fowler, Martin, 110
getAllParams(), 102
getInstance(), 44, 102, 104, 149
global variables, 149, 454
instantiating objects as a dirty business, 147
interceptor methods, table of, 58
interfaces, 47
introducing dependencies in the name of
good design, 149
is_callable(), 67–68
Java and, 4
■ INDEX
503
late static bindings, 49
leaving an overzealous class unchanged,
109
magic methods, 62
making code amenable to variation at
runtime, 146
minimizing top-down control and
dependencies, 100
Minion class, 146
NastyBoss class, 146–147
orthogonality, definition of, 104
overloading, 58
parallel conditionals, 149, 454
PDO class, code listing, 43
performing a task in deliberate ignorance of
its wider context, 25
phpDocumentor, 459
polymorphism, 106, 110, 454
programming-related web sites, list of, 464
read(), 102
reading from and writing to configuration
files, code example, 102
recruit(), 148
reference articles and books, list of, 463
registerCallback(), 67–68
responsibility and the controlling code, 103
reusability, promoting, 455
sale(), 67
simplexml_load_file(), 52
Singleton pattern, 149
SpreadSheet class, 50
static elements, characteristics of, 43
static factory method, 49
static methods, definition of, 42
test frameworks, benefits of, 459
$this pseudo-variable, 42
tight coupling, causes of, 454
__toString(), 65
well-designed objects as self-enclosed, 454
write(), 102
See also design patterns
object-relational impedance mismatch, 276
objects
casting an object to a string, 16
classes and objects, understanding, 15
definition of, 16
identifiers, 16
initial rise of, in PHP, 11
new operator, 16, 21
pass-by-reference rather than pass-by-value,
12–13
PEAR and object-oriented programming, 13
PHP 3 and, 11
PHP 4 and, 12
PHP 5 and, 13
PHP 5.3 and namespaces, 14
PHP 6 and, 14
properties, setting dynamically, 18
taking a design-oriented approach to
projects, 14
__toString(), 16
var_dump(), 16
Zend Engine (ZE3), 12, 14
See also classes
ObjectWatcher class, code listing, 292
Observable interface, code listing, 204
Observer pattern
attach(), 204–206, 209
class diagram, 207
detach(), 204–205, 209
doUpdate(), 206
getStatus(), 206
handleLogin(), 203
implementing, 204
Logger class, 203
Login class, 203–204
LoginObserver class, 206
notify(), 204–205
Observable interface, code listing, 204
overview of, 202
PEAR and, 332
SplObjectStorage class, code listing, 208
Standard PHP Library (SPL), 208
update(), 205
user access example, code listing, 203
onConsecutiveCalls(), 391
operations, 112
OperatorExpression class, 194
operators
instanceof, 31, 83, 108
new, 16, 21
optional element, 340
orthogonality
definition of, 104
■ INDEX
504
orthogonal code, advantages of, 104
output attribute, 448
outputAddresses(), 23
overloading, 58
override attribute, 414
Overview screen, 443
overwrite attribute, 422
■ P
package command, 341
package element, 339
@package tag, 351, 353
package.xml, 327, 435
adding the lib directory to the include path,
337
api element, 336
channel element, 335
contents element, 336
dependency elements, table of, 339
description element, 335
description of, 334
Dialekt package, directory and file structure,
337
dir element, 336
elements of, 334
file element, 336
file roles, table of, 336
lead element, 335
license element, 336
name element, 335
notes element, 336
package archive (tarball), 336
phprelease, list of elements, 340
privileges and default role locations, 337
release element, 336
stability element, 336
summary element, 335
uri element, 335
user element, 335
XML declaration, 334
packages
building from scratch versus purchasing,
317
definition of, 71
evaluating, 318
original versus reusable code, 319
PEAR, 318
prepending package names to class names,
72
using the file system to simulate packages,
76
Page Controller pattern, 222
AddVenueController class, code listing, 259
advantages and disadvantages of, 261
controller element, 258
error.php, 258
exit(), 258
forward(), 259
include(), 258
overview of, 257
process(), 259
venues.php, 261
view element, 258
PageController class, code listing, 258
parallel conditionals, 141, 149, 454
@param tag, 355
parameters, 112
ParamHandler class, 104, 108
parent class, 27
parent keyword, 33, 35, 42
Parser class, code listing, 474
pattern languages, 125
patternset element
description of, 418
table of attributes, 419
PDO class, 404
code listing, 43
getInstance(), 44
PEAR, 6, 459
acquire(), 333
adding the lib directory to the include path,
337
addObserver(), 333
as element, 341
browsing repository packages, 323
channel element, 339
channel-discover command, 328
channel-info command, 328
channels, 327
Config class, 330
Config_Container class, 330
Config.php, 330
config-get command, 324
config-show command, 324
■ INDEX
505
connect(), 138
creating PEAR packages, 334
Data Source Name (DSN), 138
dependencies tag, 339
dependency elements, table of, 339
description of, 323
difficulties in managing multiple
interdependent packages, 341
distinguishing between Exception types,
332
downloading and installing a package from
the command line, 327
error handling, 331
exclude element, 339
file roles, table of, 336
finding API documentation, 330
generating archived and compressed
packages for shipment, 341
getBacktrace(), table of elements, 331
getCause(), 332–333
getCode(), 331
getErrorClass(), 332
getErrorData(), 332
getErrorMethod(), 332
getMessage(), 331
handling initial configuration options, 325
handling project installations with, 407
hosting a channel with a third-party
provider, 342
install element, 341
installconditions element, 341
installing packages with the install
command, 326
isError(), 331
Linux systems, 324
Log package, installing, 326
managing packages, 344
max element, 339
MDB2 package, 138
MDB2_Driver_Common class, 138
migrating to, 325
min element, 339
MyConfig class, code example, 330
notifyError(), 333
object-oriented programming and, 13
Observer pattern, 332
optional element, 340
package command, 341
package element, 339
package.xml, 327, 334
pear command line application, 324
PEAR Foundation Classes, 324
PEAR installer, using, 320
PEAR_Error class, 52, 331
PEAR_Exception class, 332
PEAR2_SimpleChannelFrontend, managing
a channel, 343
PEAR2_SimpleChannelServer, defining a
channel, 342
pearinstaller element, 339
Phing and, 408
phprelease, list of elements, 340
phpunit alias, 328
PHPUnit package, installing, 328
PHPUnit, installing, 382
privileges and default role locations, 337
process(), 333
Pyrus, 324
recommended element, 339
required dependencies, installing, 327
required element, 339
required extensions, 325
root privileges, requirements for, 326
runing pear install with the -o flag, 327
sample list of available packages, 318
setting an error_reporting directive, 330
Unix systems, 324
uri element, 339
using PEAR packages, 329
using Pyrus channel management to serve
PEAR packages, 342
using the naming convention common to
PEAR packages, 78
wget command, 327
XML_Feed_Parser package, 332
See also PHP
pear package command, 448
PEAR_Exception class, 332
pearinstaller element, 339
performOperations(), 293
Perl, 11
persistence classes, illustration of, 312
PersistenceFactory class, illustration of, 301
Phing, 7, 439, 459
■ INDEX
506
acquiring and installing, 408
adding a dependency to a build file, 410
Ant, 407
begintoken attribute, 420
build.xml, 407, 409
building up include and exclude rules, 417
clean argument, 425
commenting build files, 409
composing the build document, 408
copy element, table of attributes, 422
Copy task, 420, 422
-D flag, 413
defaultValue attribute, 424
delete element, 425
deleting a build directory, 425
description attribute, 411
description of, 407
dir attribute, 417
echo element, 423
Echo task, 421
endtoken attribute, 420
ensuring that properties are populated, 416
env prefix in a property reference, 415
excludes attribute, 417
file attribute, 422
FileSet data type, 417
fileset element, table of attributes, 417
filterchain element, 419–420
filters, 419
id attribute, 417
if attribute, 412–413
includes attribute, 417
input element, table of attributes, 424
installing applications, 320
main task, 413
override attribute, 414
overriding the project element’s default
attribute, 410
overwrite attribute, 422
patternset element, table of attributes, 419
PEAR and, 408
phing command, 408
project element, 409
-projecthelp flag, 411
promptChar attribute, 424
properties, built-in, 415
properties, declaring, 412
properties, setting on the command line,
414
propertyName attribute, 424
replacetokens element, 420
ReplaceTokens filter, 420
setpass target, 424
srclib fileset element, 422
StripPhpComments task, 419
target element, table of attributes, 414
targets, setting up dependencies, 410
tasks, definition of, 421
unless attribute, 412–413
uses for, 408
using make as a build solution, 407
-v flag, 408
ways of setting a property, 416
when a property isn’t found, 415
XML declaration, including, 409
PHP
Atkinson, Leon, 5
Fuecks, Harry, 5
Gutmans, Andi, 5, 11
hinted return types, 156
Lerdorf, Rasmus, 5, 11
namespaces and, 455
origins of, 4
pass-by-reference rather than pass-by-value,
12–13
PEAR, 6, 13
Phing, description of, 407
PHP 3 and objects, 11
PHP 4 and objects, 12
PHP 4 and var keyword, 17, 35
PHP 5 and objects, 13
PHP 5, release features, 453
PHP 5.3 and namespaces, 14, 71
PHP 6 and objects, 14
PHP as a loosely typed language, 22
PHP/FI 2.0, 11
procedural programming and, 14
projects turning into design disasters, 3
Suraski, Zeev, 5, 11, 13
taking a design-oriented approach to
projects, 14
Unicode string handling, 14
Zend Engine (ZE3), 12, 14
Zend Engine 2, 5, 453
■ INDEX
507
See also PEAR
PHP_CodeBrowser
installing and using, 433
phpcb command line tool, 434
PHP_CodeSniffer, 433
php.ini, 79, 337
phpdoc command, 349
PHPDocumentor, 7, 321, 431, 459
adding comments to source code, 350
@author tag, 352
Beaver, Greg, 353
class relationships, viewing, 350
classes, documenting, 352
@copyright tag, 352
creating hyperlinks in documentation, 356
-d flag, 349
-dn flag, 349
DocBlock comments, 350, 352
documentation, generating, 349
documenting methods, 355
documenting private elements, 354
documenting properties, 353
downloading and installing, 348
file-level documentation, providing, 353
-h flag, 348
@license tag, 353
@link tag, 358
making a reciprocal link, 358
namespaces and, 353
navigating and examing packages, 351
output menu, sample page, 349
@package tag, 351, 353
@param tag, 355
phpdoc command, 349
-pp flag, 354
@return tag, 355
running as a command line tool, 349
@see tag, 356
SourceForge.net, 348
-t flag, 349
tags, defining, 351
-ti flag, 349
@uses tag, 358
@var tag, 353
See also documentation
phprelease, list of elements, 340
phpuc command line tool, 438
amending the config.xml and build.xml
files, 442
bug in the phpuc graph command, 442
project command, using, 441
phpUnderControl
amending the CruiseControl environment
to support phpUnderControl, 439
ezcGraph, installing, 438
installing, 438
PHPUnit, 7, 430
addUser(), 385
AddVenueTest class, code listing, 397
assertEquals(), 384
assertions, definition of, 383
assertions, support for, 384
AssertThat(), 387
AssertTrue(), 386
behavior verification, 389
Bergmann, Sebastian, 382
brittle nature of many test harnesses, 404
centralizing test fixtures into Object
Mothers, 405
checking the behavior of the UserStore class
when an operation fails, 385
combining real and mocked components in
testing, 405
constraints, 386
creating a minimal test case class, 382
creating a test method, 383
creating a Web UI superclass, 398
DBFace class, 404
debugging tests, 404
expects(), 389–390
exporting a Selenium test as a PHPUnit
class, 402
fail(), 385
faking the context of the class you are
testing, 389
fixture, definition of, 383
fluent interface, 389–390
getMock(), 389
getUser(), 393
handleRequest(), 395
installing using PEAR, 382
is_array(), 393
matcher methods, table of, 390
method(), 390
mock objects, generating, 389