Skip to content

Instantly share code, notes, and snippets.

@thomasbellio
Last active August 29, 2015 14:07
Show Gist options
  • Save thomasbellio/03bf07f5566125c9ce39 to your computer and use it in GitHub Desktop.
Save thomasbellio/03bf07f5566125c9ce39 to your computer and use it in GitHub Desktop.
How the hack (doesn't) handles generic classes
<?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));
}
}
<?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