Skip to content

Instantly share code, notes, and snippets.

@mathiasverraes
Created November 24, 2016 18:55
Show Gist options
  • Select an option

  • Save mathiasverraes/8fcb6c8065201728f311fb0b43bee3a8 to your computer and use it in GitHub Desktop.

Select an option

Save mathiasverraes/8fcb6c8065201728f311fb0b43bee3a8 to your computer and use it in GitHub Desktop.
duck typing
<?php
// duck typing
final class Foo {
public function bar ($object) {
$object->quack();
}
}
// Because we know nothing about $object, it's only by calling quack that we can
// tell whether object supports quack()
// Same but with a language construct that statically declares the need for $object
// to support a quack method. It could now be verified at compile time.
final class Foo {
public function bar ($object :: quack()) {
$object->quack();
}
}
@Harrisonbro
Copy link

@mathiasverraes Do other languages have this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment