Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deshack/2cd919cbc5d257ce6367f54af12c8ec3 to your computer and use it in GitHub Desktop.
Save deshack/2cd919cbc5d257ce6367f54af12c8ec3 to your computer and use it in GitHub Desktop.
PHP7 usage of return type declarations
<?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