Last active
December 11, 2015 04:28
-
-
Save jayzeng/4545096 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Duck typing | |
class Car | |
{ | |
public function run() { | |
return 'car is running'; | |
} | |
} | |
class Truck | |
{ | |
public function run() { | |
return 'my truck is moving'; | |
} | |
} | |
class VehicleRunner | |
{ | |
// doesn't indicate specific type | |
// be flexible in terms of what gets passed in | |
public function run($vehicle) { | |
return $vehicle->run(); | |
} | |
} | |
$vehicle = new VehicleRunner(); | |
$vehicle->run( new Car() ); | |
$vehicle->run( new Truck() ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment