Created
November 27, 2015 13:49
-
-
Save tpavlek/8e82e9b94aa4d99465f6 to your computer and use it in GitHub Desktop.
Value of late-static typehints
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
class AbstractValueObject { | |
public static funtion sum(static ...$values) { | |
$total = 0; | |
foreach ($values as $value) { | |
$total += $value->getIntegerRepresentation(); | |
} | |
return new static($total); | |
} | |
} | |
class OtherValueObject extends AbstractValueObject { | |
} | |
class ConcreteValueObject extends AbstractValueObject { | |
} | |
$values = [ new ConcreteValueObject(), new OtherValueObject(), new ConcreteValueObject() ]; | |
// We want this to throw an error, because it's trying to sum one instance of OtherValueObject which isn't the same type as the | |
// static call. | |
$total = ConcreteValueObject::sum($values); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment