Last active
August 29, 2015 14:07
-
-
Save thomasbellio/03bf07f5566125c9ce39 to your computer and use it in GitHub Desktop.
How the hack (doesn't) handles generic classes
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
<?hh namespace Repositories\Generics; | |
class BaseRepository<T> | |
{ | |
/** | |
* Saves the model | |
* @param T $model | |
* @return bool true if the model was saved | |
*/ | |
public function save(T $model) | |
{ | |
var_dump(gettype($model)); | |
} | |
} |
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
<?hh namespace Tests\Repositories\Generics; | |
use TestCase; | |
use Repositories\Generics\BaseRepository; | |
use User; | |
use App; | |
use ReflectionClass; | |
class BaseRepository extends TestCase | |
{ | |
/** | |
* The user repository | |
* | |
* @var UserRepository | |
*/ | |
private $userRepository; | |
public function testSave() | |
{ | |
$user = App::make('User'); | |
$userRepo = new BaseRepository<User>(); | |
// This shouldn't work but it does. | |
$userRepo->save('string'); | |
$userRepo->save($user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment