Finish";
}
}
protected function verifyEIN($ein)
{
return TRUE;
}
}
$employee = new Employee("123-45-6789");
?>
Attempts to call verifyEIN() from outside of the class will result in a fatal error
because of its protected scope status.
Abstract
Abstract methods are special in that they are declared only within a parent class but are
implemented in child classes. Only classes declared as abstract can contain abstract
methods. You might declare an abstract method if you want to define an application
programming interface (API) that can later be used as a model for implementation. A
developer would know that his particular implementation of that method should work
provided that it meets all requirements as defined by the abstract method. Abstract
methods are declared like this:
abstract function methodName();
Suppose that you want to create an abstract Employee class, which would then
serve as the base class for a variety of employee types (manager, clerk, cashier, etc.):
CHAPTER 6 ?– O BJECT-ORIENTED PHP 181
abstract class Employee
{
abstract function hire();
abstract function fire();
abstract function promote();
abstract demote();
}
This class could then be extended by the respective employee classes, such as
Manager, Clerk, and Cashier. Chapter 7 expands upon this concept and looks much
more deeply at abstract classes.
Final
Marking a method as final prevents it from being overridden by a subclass.
Pages:
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260