Created
April 11, 2012 20:07
-
-
Save baileylo/2362087 to your computer and use it in GitHub Desktop.
Example why you should use type hinting in php where applicable.
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 setUserName(User $user, $new_username) { | |
$user->Profile->setUserName($new_username); | |
} | |
function setUsername1($user, $new_username) { | |
$user->Profile->setUserName($new_username); | |
} | |
// Catchable fatal error: Argument 1 passed to setUserName() must be an instance | |
// of User, array given, called in FILE on line N and defined in FILE on line N | |
setUserName(array(), 'Logan'); | |
//Trying to get property of non-object in FILE on line N | |
//Fatal error: Call to a member function setUserName() on a non-object in FILE on line N | |
setUserName1(array(), 'Logan'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment