WHAT'S HOT
Prev | Current Page 364 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"


This is helped by using type hinting in functions. Type hinting is used to tell the PHP interpreter information
about the parameters passed to a function. Consider the function in listing 17.8.
Listing 17.8 Type hinting provides information about function parameters
function displayPerson(ZFiA_Person $person) 1
{
echo $person->fullName();
}
1 Provide ZFiA_Person type hint in function declaration
To create a type hint, all we need to do is include the type of the function parameter, ZFiA_Person in this
case (#1). If we try to pass any other kind of object to this function then we get this error message:
Catchable fatal error: Argument 1 passed to displayPerson() must be an instance of ZFiA_Person, string
given, called in type_hinting.php on line 18 and defined in type_hinting.php on line 11
As should be obvious, interfaces are not required for PHP coding as PHP is not a statically typed language
and will do the right thing in the majority of cases. The main benefit of interfaces is for the programmer as it
helps make code self-documenting.
Another feature of PHP 5 that is used by the Zend Framework to make programmers??™ lives easier is the socalled
???magic methods???. These are special methods that PHP calls automatically when required, allowing the
programmer to provide a cleaner interface to the class.


Pages:
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
pustaki szklane House Extension Kąty Rybackie noclegi kasyno Kołobrzeg