Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface Vehicle {
- public function whatAreYou();
- }
- class Plane implements Vehicle {
- public function whatAreYou() {
- print "I'm a plane.";
- }
- }
- class Bicycle implements Vehicle {
- public function whatAreYou() {
- print "I'm a bicycle.";
- }
- }
- // Declare $vehicle of the type "Vehicle". It can now hold any derivative of the "Vehicle" interface.
- Vehicle $vehicle;
- // This is acceptable:
- $vehicle = new Bicycle();
- // This works too!
- $vehicle = new Plane();
- // But really none of this matters, since a PHP variable can hold anything anyway. but with languages as C++ or Java, a variable always has a type, so even a boolean wouldn't fit in an integer. Nor a float in a boolean (etc).
Advertisement
Add Comment
Please, Sign In to add comment