May 2017
Intermediate to advanced
340 pages
8h 16m
English
First, we will create an interface for the stack so that we can use it in different implementations, and can ensure that all implementations have some similarity to each other. Let us write the simple interface for the stack:
interface Stack { public function push(string $item); public function pop(); public function top(); public function isEmpty(); }
As we can see from the preceding interface, we kept all stack functions inside the interface because the class that it is implementing must have all these mentioned functions, otherwise, else a fatal error will be thrown during runtime. Since we are implementing the stack using a PHP array, we are going to use some existing PHP functions for push, pop, ...
Read now
Unlock full access