Skip to content

Instantly share code, notes, and snippets.

@jayzeng
Last active December 11, 2015 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayzeng/4545096 to your computer and use it in GitHub Desktop.
Save jayzeng/4545096 to your computer and use it in GitHub Desktop.
<?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