Created
July 6, 2017 02:33
-
-
Save fernandodebrando/a00d2ce1d6065dd5a514ed6be0e06a97 to your computer and use it in GitHub Desktop.
Object typehint
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 | |
function acceptsObject(object $obj) { | |
//... | |
} | |
// Este código será analisado estaticamente e está correto | |
acceptsObject(json_decode('{}')); | |
// Este código será analisado estaticamente e está correto | |
acceptsObject(new \MyObject()); | |
// Aqui será analisado estaticamente e contém erro | |
// e lançaria um TypeError em tempo de execução | |
acceptsObject("Ceci n'est pas une object."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment