Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
\Drupal\Component\DependencyInjection\Container::createService and \Drupal\Component\DependencyInjection\PhpArrayContainer::createService have a long block of code inthe getService method that was designed to improve performance by minimising the use of reflection when instantiating classes with varying amounts of arguments. This is now unnecessary as we're not having to cater to PHP 5.5
Proposed resolution
Use php's variable length argument lists to make this much simpler.
Remaining tasks
- Extend patch to cover both container classes
- Commit
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#14 | interdiff_10_14.txt | 2.47 KB | govind.maloo |
#14 | 2962978-14.patch | 5.25 KB | govind.maloo |
#10 | 2962978-10.patch | 2.64 KB | govind.maloo |
Comments
Comment #2
msankhala CreditAttribution: msankhala as a volunteer and at Srijan | A Material+ Company commentedComment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedWe can not do it until March 6, 2019 because #2842431: [policy] Remove PHP 5.5, 5.6 support in Drupal 8.7.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm not an advocate for PHP 5.5 supporting. And I have 0 friends who agree with this prolonged support.
But I must admit that I personally like these Christmas trees, which you propose to replace with soulless
if/else
construction :pAlthough progress makes sense, of course. Thanks!
Comment #5
msankhala CreditAttribution: msankhala as a volunteer and at Srijan | A Material+ Company commentedIt's a half Christmas tree though :) Trees are good as data structure but not as code branching. :P
Comment #9
jonathanshaw5.5. support is now dropped.
If we can now use $arguments, then we can use it for more than 10 arguments and drop the whole reflection class thing?
So the code becomes
Comment #10
govind.maloo CreditAttribution: govind.maloo at Salsa Digital commentedComment #11
govind.maloo CreditAttribution: govind.maloo at Salsa Digital commentedComment #12
jonathanshawThank @govind.maloo!
The test fail is a random (#3103492: Random fail in WidgetUploadTest, so we can ignore that.
However, we need to patch the same problem in Container.php as well as PhpArrayContainer.php. Resetting to Needs Work for that.
Comment #13
jonathanshawComment #14
govind.maloo CreditAttribution: govind.maloo at Salsa Digital commentedComment #15
pandaski CreditAttribution: pandaski commentedThis is an awesome and clean solution to use "Variable-length argument lists"
Comment #16
alexpottCrediting @msankhala for filing the issue. @jonathanshaw for coming up with the solution.
Committed and pushed 79938c6da5 to 9.0.x and b040e57c1b to 8.9.x. Thanks!