Created
June 6, 2016 15:47
-
-
Save deshack/2cd919cbc5d257ce6367f54af12c8ec3 to your computer and use it in GitHub Desktop.
PHP7 usage of return type declarations
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
<?php | |
class User {} | |
function getUserWrong() : User { | |
return []; | |
} | |
getUserWrong(); | |
// PHP Warning: Uncaught TypeError: Return value of getUserWrong() must be an instance of User, array returned | |
function getUser() : User { | |
return new User; | |
} | |
var_dump(getUser()); | |
// object(User)#1 (0) { | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment