Skip to content

Replace get_class() calls by ::class #21016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace get_class() calls by ::class
  • Loading branch information
alamirault committed May 29, 2025
commit 65599c4cec1f2bc3661fad1fe9e3594146bd65f7
2 changes: 1 addition & 1 deletion components/options_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ can change your code to do the configuration only once per class::
public function __construct(array $options = [])
{
// What type of Mailer is this, a Mailer, a GoogleMailer, ... ?
$class = get_class($this);
$class = $this::class;

// Was configureOptions() executed before for this class?
if (!isset(self::$resolversByClass[$class])) {
Expand Down
2 changes: 1 addition & 1 deletion components/property_info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class exposes public methods to extract several types of information:
$propertyInfo->getProperties($awesomeObject);

// Good!
$propertyInfo->getProperties(get_class($awesomeObject));
$propertyInfo->getProperties($awesomeObject::class);
$propertyInfo->getProperties('Example\Namespace\YourAwesomeClass');
$propertyInfo->getProperties(YourAwesomeClass::class);

Expand Down
2 changes: 1 addition & 1 deletion components/yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ You can make it convert to a ``DateTime`` instance by using the ``PARSE_DATETIME
flag::

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

Dumping Multi-line Literal Blocks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion console/verbosity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ level. For example::

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

// alternatively you can pass the verbosity level PHP constant to writeln()
Expand Down
2 changes: 1 addition & 1 deletion doctrine/associations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ by adding JOINs.
$category = $product->getCategory();

// prints "Proxies\AppEntityCategoryProxy"
dump(get_class($category));
dump($category::class);
die();

This proxy object extends the true ``Category`` object, and looks and
Expand Down
2 changes: 1 addition & 1 deletion security/user_providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ command will generate a nice skeleton to get you started::
public function refreshUser(UserInterface $user): UserInterface
{
if (!$user instanceof User) {
throw new UnsupportedUserException(sprintf('Invalid user class "%s".', get_class($user)));
throw new UnsupportedUserException(sprintf('Invalid user class "%s".', $user::class));
}

// Return a User object after making sure its data is "fresh".
Expand Down
6 changes: 3 additions & 3 deletions service_container/service_subscribers_locators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ to handle their respective command when it is asked for::

public function handle(Command $command): mixed
{
$commandClass = get_class($command);
$commandClass = $command::class;

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

public function handle(Command $command): mixed
{
$commandClass = get_class($command);
$commandClass = $command::class;

if ($this->locator->has($commandClass)) {
$handler = $this->locator->get($commandClass);
Expand Down Expand Up @@ -328,7 +328,7 @@ attribute::

public function handle(Command $command): mixed
{
$commandClass = get_class($command);
$commandClass = $command::class;

if ($this->handlers->has($commandClass)) {
$handler = $this->handlers->get($commandClass);
Expand Down
Loading