Last active
December 19, 2015 01:19
-
-
Save mnapoli/5874705 to your computer and use it in GitHub Desktop.
PHP 5.5 ::class feature
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 | |
use A\Long\Namespace\User; | |
use Some\Namespace\ProductService; | |
// Doctrine: get entity | |
$user = $entityManager->find('A\Long\Namespace\User', 1234); | |
$user = $entityManager->find(User::class, 1234); | |
// Doctrine repositories | |
$repository = $em->getRepository('A\Long\Namespace\User'); | |
$repository = $em->getRepository(User::class); | |
// Doctrine Query Builder | |
$qb->select('u') | |
->from('A\Long\Namespace\User', 'u') | |
->where('u.id = ?1') | |
->orderBy('u.name', 'ASC'); | |
$qb->select('u') | |
->from(User::class, 'u') | |
->where('u.id = ?1') | |
->orderBy('u.name', 'ASC'); | |
// DI container | |
$container->get('Some\Namespace\ProductService'); | |
$container->get(ProductService::class); | |
// Another with DI container | |
$container->set('foo') | |
->bindTo('Some\Namespace\ProductService') | |
->withArguments(/* ... */); | |
$foo = $container->get('foo'); | |
$container->set('foo') | |
->bindTo(ProductService::class) | |
->withArguments(/* ... */); | |
$foo = $container->get('foo'); | |
// PHPUnit | |
$this->assertInstanceOf('A\Long\Namespace\User', $foo); | |
$this->assertInstanceOf(User::class, $foo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment