Skip to content

Commit 3d83f8d

Browse files
committed
minor #21016 Replace get_class() calls by ::class (alamirault)
This PR was merged into the 6.4 branch. Discussion ---------- Replace `get_class()` calls by `::class` This change was made in symfony codebase in 2022 symfony/symfony#47401. I think we can use same rule in our examples Commits ------- 65599c4 Replace get_class() calls by ::class
2 parents facaf80 + 65599c4 commit 3d83f8d

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

components/options_resolver.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ can change your code to do the configuration only once per class::
922922
public function __construct(array $options = [])
923923
{
924924
// What type of Mailer is this, a Mailer, a GoogleMailer, ... ?
925-
$class = get_class($this);
925+
$class = $this::class;
926926

927927
// Was configureOptions() executed before for this class?
928928
if (!isset(self::$resolversByClass[$class])) {

components/property_info.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class exposes public methods to extract several types of information:
131131
$propertyInfo->getProperties($awesomeObject);
132132

133133
// Good!
134-
$propertyInfo->getProperties(get_class($awesomeObject));
134+
$propertyInfo->getProperties($awesomeObject::class);
135135
$propertyInfo->getProperties('Example\Namespace\YourAwesomeClass');
136136
$propertyInfo->getProperties(YourAwesomeClass::class);
137137

components/yaml.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ You can make it convert to a ``DateTime`` instance by using the ``PARSE_DATETIME
296296
flag::
297297

298298
$date = Yaml::parse('2016-05-27', Yaml::PARSE_DATETIME);
299-
var_dump(get_class($date)); // DateTime
299+
var_dump($date::class); // DateTime
300300

301301
Dumping Multi-line Literal Blocks
302302
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

console/verbosity.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ level. For example::
6060

6161
// available methods: ->isQuiet(), ->isVerbose(), ->isVeryVerbose(), ->isDebug()
6262
if ($output->isVerbose()) {
63-
$output->writeln('User class: '.get_class($user));
63+
$output->writeln('User class: '.$user::class);
6464
}
6565

6666
// alternatively you can pass the verbosity level PHP constant to writeln()

doctrine/associations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ by adding JOINs.
447447
$category = $product->getCategory();
448448

449449
// prints "Proxies\AppEntityCategoryProxy"
450-
dump(get_class($category));
450+
dump($category::class);
451451
die();
452452

453453
This proxy object extends the true ``Category`` object, and looks and

security/user_providers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ command will generate a nice skeleton to get you started::
425425
public function refreshUser(UserInterface $user): UserInterface
426426
{
427427
if (!$user instanceof User) {
428-
throw new UnsupportedUserException(sprintf('Invalid user class "%s".', get_class($user)));
428+
throw new UnsupportedUserException(sprintf('Invalid user class "%s".', $user::class));
429429
}
430430

431431
// Return a User object after making sure its data is "fresh".

service_container/service_subscribers_locators.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ to handle their respective command when it is asked for::
3636

3737
public function handle(Command $command): mixed
3838
{
39-
$commandClass = get_class($command);
39+
$commandClass = $command::class;
4040

4141
if (!$handler = $this->handlerMap[$commandClass] ?? null) {
4242
return;
@@ -94,7 +94,7 @@ in the service subscriber::
9494

9595
public function handle(Command $command): mixed
9696
{
97-
$commandClass = get_class($command);
97+
$commandClass = $command::class;
9898

9999
if ($this->locator->has($commandClass)) {
100100
$handler = $this->locator->get($commandClass);
@@ -328,7 +328,7 @@ attribute::
328328

329329
public function handle(Command $command): mixed
330330
{
331-
$commandClass = get_class($command);
331+
$commandClass = $command::class;
332332

333333
if ($this->handlers->has($commandClass)) {
334334
$handler = $this->handlers->get($commandClass);

0 commit comments

Comments
 (0)