-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Please start using PHP 5.5's "::class" instead of plain strings as FQCNs #4068
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
Comments
💯 |
💯 Let's keep Magento's code quality moving forward!!!! Definitely agree! |
Thank you for this proposal. |
Before rushing into using new[er] PHP features, please make sure you know what it is your doing. The examples given are stupid. Using IE: What you might want, for clarity, could be:
Here I have assumed that if someone creates a subclass of Magento\Framework\View\TemplateEngine\Xhtml\ResultFactory it is preferred for the instanceName property to remain to be Magento\Framework\View\TemplateEngine\Xhtml\ResultFactory unless the constructor is specifically modified. If it is preferred that the instance name FOR THIS CLASS should reflect the name of the actual class by default, then and only then does it become preferably to use
As such, there is no reason to assume that there should even be a single instance of ::class being used anywhere in the code. Based on the current code, CLASS is more appropriate as it matches the current behaviour[to change the DEFAULT value of instanceName requires changing the constructor] Moreover, since the Magento object manager passes the string value it thinks instance name should be to objects it creates - in general it won't make any difference how the class constructor assigns a default value. Changing thousands of files in a meaningless way is simply stupid. It was stupid with the first patch of this year[which modified every file to change the end year copyright date to 2016 for no reason] and it would be stupid here. |
I was more refering to the first case. And for test classes mostly and for wherever it's fit, not saying we should use PS: I think you can get your point across without having to use the word "stupid" so many times. We get it: it's stupid. public function __construct(
ObjectManagerInterface $objectManager,
$instanceName = false
) {
$this->objectManager = $objectManager;
// If the instance name was not specified, then use the class name and namespace as defined in this php file
if ($instanceName)
{
$this->instanceName = $instanceName;
} else {
$this->instanceName = __CLASS__;
}
} |
Simple script with allow convert many place automatic
|
Internal issue MAGETWO-53555 |
You're still doing it: 3be18f3#diff-35047a76fe781049c19099b882f4d183R11 I've seen loads of snippets in magento SO site using strings, because I assume that's what they see in the codebase. |
http://devdocs.magento.com/guides/v2.0/coding-standards/code-standard-php.html Please review and if you'd like to submit edits or enhancements, please create a PR on our devdocs repo! Thanks for all contributions. |
It should be fixed. Investigating why it appeared in recent commit. |
Closed as this issue has been already fixed in 2638640 |
Any plans to backport this issue or is it planned for 2.2 only? |
As I understand it, no backport is planned "by default" and closed tasks are not tracked by the core team neither (see here for an detailed official Magento Inc.'s response about that). |
I don't really see the point in backporting this? It brings no new features, it fixes no bugs, ... The only reason I can see for backporting this, is it will make backporting other fixes easier, as there will be less conflicts in the code. Just my 2 cents :) |
Personally, I don't really see the point in not backporting something right away (unless it contains backward-incompatible changes), even if it just fixes the code style. |
Steps to reproduce
::class
Expected result
Actual result
Even recent commits use plain strings. It's PHP 5.5+. Come on. Is there a reason why you haven't moved to using
::class
already? The more you use strings, the harder the change. I suggest you start using them in 3... 2... 1.The text was updated successfully, but these errors were encountered: