Created
November 24, 2016 18:55
-
-
Save mathiasverraes/8fcb6c8065201728f311fb0b43bee3a8 to your computer and use it in GitHub Desktop.
duck typing
This file contains 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 | |
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mathiasverraes Do other languages have this?