Problem/Motivation
The commit of #2087231: Add a PluginBase in the Core namespace with t() as a helper method added a PluginBase class to Drupal\Core\Plugin which compromised the ContextAwarePluginBase in the same directory since it referenced a "PluginBase" class in Drupal\Component. According the official PHP documentation this should never happen, but for some inexplicable reason it does.
Proposed resolution
Use a different alias, so we avoid the collission altogether.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Dependent issues
This bug blocks many issues for several projects, including:
- #2136197: Move field/instance/widget/formatter settings out of annotation / plugin definition
- #2144457: Port the "payment amount comparison" Rules condition
Original report by @username
The commit of #2087231: Add a PluginBase in the Core namespace with t() as a helper method added a PluginBase class to Drupal\Core\Plugin which compromised the ContextAwarePluginBase in the same dir since it referenced a "PluginBase" class in Drupal\Component. I don't know what tests didn't start failing for this as there is test coverage that does instantiate context aware plugins, but my attempt to use them manually subsequently of this patch being committed cause serious issues. This patch provides a simple fix for the problem by renaming the "as" statement.
I also removed a use statement that was not being utilized in the class since I was already messing with the use statements.
Eclipse
Comment | File | Size | Author |
---|---|---|---|
#18 | drupal_2170471_18.patch | 1.02 KB | Xano |
Comments
Comment #1
larowlanComment #2
clemens.tolboomAs my issue #2176275: Fatal thrown: Cannot use ... PluginBase because the name is already in use was closed as a duplicated of this one this really needs a better report.
Comment #3
EclipseGc CreditAttribution: EclipseGc commentedYes it is a dupe. I'm not sure I see the point in testing since this was clearly "our bad" by introducing stuff php doesn't support. It was really just an ignorance issue, not a functionality or unit testable thing. However, if we still feel like putting tests on, sure why not, except that it has nothing to do with plugins, that's just where we introduced stuff php doesn't support to our demise. Dawehner's suggestion of figuring out how to evaluate the entire code base is more on target.
Sorry my bug report sucks, but I don't think this needs tests, nor do I think it needs further review. I'm not trying to be a jerk, so if you really disagree feel free to get a few others to chime in here.
Eclipse
Comment #4
tstoecklerNot going to demote, but I don't see why we wouldn't provide a unit test for ContextAwarePluginBase in general which clearly would have caught this problem?!
Comment #5
clemens.tolboomAs I've reported in #2176275: Fatal thrown: Cannot use ... PluginBase because the name is already in use my error is gone. I cannot reproduce it. And this patch is not in yet. So we can be sure we will have this kind of bug again in the near future.
When people search for " because the name is already in use " they land on a duplicate issue.
This issues summary deserves at least the exception thrown and steps to reproduce.
I'm fine with no tests as we currently have a solution (workaround) to replace the 'existing' alias into a non-existing.
But it still is a nasty issue.
Comment #6
EclipseGc CreditAttribution: EclipseGc commented@clemens.tolboom
Feel free to update the issue summary. I'm notoriously bad with them.
@tstoeckler
We had a use statement with an alias in a class, we then introduced a class of the same name as the alias into the same directory structure which introduced a conflict of naming. This is clearly our fault and not something we'd have ever provided test coverage for since it's a php level expectation of how we are going to work. Why it works in some situations and fails in others is a question I cannot answer and one we should perhaps take to a higher php authority, however providing test coverage for php level behavior expectations seems fruitless to me as the most it could do is tell us whether we have an environment problem (if say this issue is php version specific). It certainly can't provide any reliable test information. It's like providing a test that checks if is_string() produces a true/false value for things that are actually strings.
Eclipse
Comment #7
clemens.tolboom@EclipseGc you're not very helpful :-(
I asked in #2 whether your exception was the same and still have no clue. So I cannot update the summary on your behalf either.
Comment #8
EclipseGc CreditAttribution: EclipseGc commentedI'll have to go break my system again to be 100% certain. Since I was actively developing a contrib module for D8, I fixed it and kept moving. It's not a thing I can do today, but I know I did it by invoking the NodeType condition. Your bug report looks like what I recall, but I can't confirm that w/o some margin of error right now. I'll see if I can find time to get back into that development environment and undo this. I don't mean to be unhelpful. I'm sorry.
Eclipse
Comment #9
clemens.tolboom@EclipseGc thanks for your context.
I'll try to update the summary during the sprint weekend :)
Comment #10
tstoecklerThanks for the explanation in #6: I was under the impression that generic unit tests for ContextAwarePluginBase i.e. for setContextValue() would have caught this bug. If that's not the case - or not *necessarily* the case - there is absolutely no point in providing those tests *in this issue*.
Comment #11
alexpottWell according to http://www.php.net/manual/en/language.namespaces.faq.php#language.namesp... this should not cause any problems at all. It should use the correct class. So setting back to needs work as I don't think that the test failures experienced can be because of this.
Comment #12
EclipseGc CreditAttribution: EclipseGc commented@alexpott
I understand your point here, and yes the docs say it works, but I'm not experiencing a test failure, I'm experiencing a manual instantiation and usage failure, and this patch solves that, which leads me to believe that we have a php version specific issue. :-(
Eclipse
Comment #13
clemens.tolboomI tried to write a test for this but failed. My Graph API has 4 PHP Fatals
Drupal\Core\Executable\ExecutablePluginBase
Drupal\Core\Plugin\ContextAwarePluginBase
Drupal\language\Plugin\Condition\Language
Drupal\node\Plugin\Condition\NodeType
of which the deepest stacktrace is
This shows I guess we needs to investigate into the autoloader process.
Using the classes through Graph API input filter generates the same fatal.
Comment #14
clemens.tolboomAttached the class diagram showing the classes in err. Note the double extends between Drupal\Component\Plugin\ContextAwarePluginBase and Drupal\Core\Plugin\ContextAwarePluginBase
Comment #15
clemens.tolboomAs reported in #2176275: Fatal thrown: Cannot use ... PluginBase because the name is already in use the my track trace fails through Reflection
My plea would be to commit this patch as I don't think we will find the root cause.
And it is at least bad practise to use an alias the way we do now.
OTOT we do have a way to reproduce this through using Graph API
Comment #16
XanoI updated the patch with the name I used in #2181999: Invalid alias for \Drupal\Component\Plugin\ContextAwarePluginBase in \Drupal\Core\Plugin\ContextAwarePluginBase so it is slightly more descriptive.
I also confirmed that the official PHP documentation says we should not be having this problem. I searched online and asked in #php to see if this is a version-specific bug, or if the documentation might be wrong, but I have not found or received an answer to that so far.
Comment #17
clemens.tolboom@Xano Ehm ... in #2181999: Invalid alias for \Drupal\Component\Plugin\ContextAwarePluginBase in \Drupal\Core\Plugin\ContextAwarePluginBase you found this bug while unit testing.
In #2176275: Fatal thrown: Cannot use ... PluginBase because the name is already in use we hoped for a test reproducing this.
Can you provide for a test (sketch) please?
See also #6 which sounds like a similar failure and #13 for a list of failure classes found till now.
Why is this removed?
Comment #18
XanoThe unit test itself wasn't what triggered the problem. It was only the context in which the problem manifested itself.
Because it was part of the previous patch.
Comment #19
XanoBased on what I've read and heard from different people, this is a parse-time error. @EclipseGc and I experience the failure when instantiating classes that extend
\Drupal\Core\Plugin\ContextAwarePluginBase
, and @clemens.tolboom experienced the same problem when analyzing a child class through reflection. These errors show up in tests, but they are not actual test failures and they are likely caused by a PHP problem.My conclusion is that, until we know what causes this, we should probably commit the working fix, especially as it does not actually change how things work. It does, however, enable everybody to start unit-testing their conditions and other context-aware plugins, which is a good thing.
Comment #20
longwaveThe patch in #2136197-17: Move field/instance/widget/formatter settings out of annotation / plugin definition triggers this failure during NodeConditionTest.
Comment #21
longwave#2136197-21: Move field/instance/widget/formatter settings out of annotation / plugin definition fails in NodeConditionTest due to this issue.
#2136197-24: Move field/instance/widget/formatter settings out of annotation / plugin definition is the failing patch plus #18 from here, and that is now passing.
Therefore I think this is RTBC.
Comment #22
XanoComment #23
alexpottBeing that this blocks #2136197: Move field/instance/widget/formatter settings out of annotation / plugin definition it is critical and the fix is trivial. Let's get this done.
Comment #24
clemens.tolboomYeah :)
As we don't have yet php 5.4 for our testbot this failure is for both 5.3 and 5.4 (on Mac locally) we may conclude this failure of PHP should be reported. We did not nailed this through a 'steps to reproduce' yet but have some insight through the failing tests.
Should we create a followup issue for this? Or let us not chase herrings aka bygones?
Comment #25
longwaveThis seems similar to https://bugs.php.net/bug.php?id=55068 - perhaps it was dependent on the order that the autoloader ended up including certain files?