Skip to content

Use PHP 5.5's ::class notation everywhere #7187

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
Dec 13, 2016

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Nov 26, 2016

While updating to use the ::class notation, I also fixed quite a few error's in the PHP code block, reformatted things a bit and updated some articles to use the AppBundle.

/fixes #7186

'Doctrine\Common' => __DIR__.'/vendor/doctrine/common/lib',
'Doctrine\DBAL\Migrations' => __DIR__.'/vendor/doctrine/migrations/lib',
'Doctrine\DBAL' => __DIR__.'/vendor/doctrine/dbal/lib',
'Doctrine' => __DIR__.'/vendor/doctrine/orm/lib',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided not to update this one, as these are not real classes. It does work in PHP, but it can confuse people.

@xabbuh
Copy link
Member

xabbuh commented Dec 1, 2016

👍

Status: Reviewed

@xabbuh
Copy link
Member

xabbuh commented Dec 1, 2016

Should we apply changes that are applicable in 2.7 too?

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@wouterj as always, you did a great and amazing work here. I love what you did in the create_framework docs. I've left some minor comments.


return new DoctrineOrmMappingsPass(
$driver,
array('Full\Namespace'),
array(Model::class),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, decided to use a more real example than Full\Namespace. Also, because ::class always is a full namespace.

3,
false,
true,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line here.

@@ -32,11 +32,11 @@ There are some helpful methods for working with the service definitions::
$definition = $container->findDefinition($serviceId);

// add a new "app.number_generator" definitions
$definition = new Definition('AppBundle\NumberGenerator');
$definition = new Definition(\AppBundle\NumberGenerator::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit strange

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a use statement could make this more readable, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ... right now the ::class is redundant in this example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not redundant. Using ::class in this situation keeps support for IDE refactoring tools (while string representations don't). So using ::class is always better.

I decided to do it this way to make the code block more readable. It contains a lot of methods to interact with definitions. Having a use statement at top of this code block doesn't make much sense and adding the use statement directly above this seemed even more redundant.

$container->setDefinition('app.number_generator', $definition);

// shortcut for the previous method
$container->register('app.number_generator', 'AppBundle\NumberGenerator');
$container->register('app.number_generator', \AppBundle\NumberGenerator::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this line looks strange too.

xabbuh added a commit that referenced this pull request Dec 13, 2016
This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #7187).

Discussion
----------

Use PHP 5.5's ::class notation everywhere

While updating to use the `::class` notation, I also fixed quite a few error's in the PHP code block, reformatted things a bit and updated some articles to use the AppBundle.

/fixes #7186

Commits
-------

7892a6a Use PHP 5.5's ::class notation
@xabbuh xabbuh merged commit cd1406f into symfony:2.8 Dec 13, 2016
xabbuh added a commit that referenced this pull request Dec 13, 2016
This PR was merged into the 2.8 branch.

Discussion
----------

Use PHP 5.5's ::class notation everywhere

While updating to use the `::class` notation, I also fixed quite a few error's in the PHP code block, reformatted things a bit and updated some articles to use the AppBundle.

/fixes #7186

Commits
-------

cd1406f Use PHP 5.5's ::class notation
@xabbuh
Copy link
Member

xabbuh commented Dec 13, 2016

Great work Wouter! I have merged it and also backported most of the changes into the 2.7 branch in 7892a6a.

@wouterj wouterj deleted the issue-7186/class-notation branch December 13, 2016 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants