Add symfony/polyfill-php84 and make use of new array functions

Created on 4 July 2024, 4 months ago
Updated 5 August 2024, 2 months ago

Problem/Motivation

PHP 8.4 will be released after Drupal 11, meaning we won't be able to use new features until we drop support for PHP 8.3. Fortunately symfony provides polyfills for many of these functions.

Steps to reproduce

Proposed resolution

Add symfony/polyfill-php84. Modernize some areas of core to use array_find, array_all, array_any and other related functions. \Drupal\Component\Assertion\Inspector is a good place to start because it has many related functions and has good unit test coverage

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 9 hours ago

Created by

πŸ‡¦πŸ‡ΊAustralia mstrelan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mstrelan
  • Status changed to Needs work 4 months ago
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Needs work for the remaining functions in the Inspector class.

  • Pipeline finished with Success
    4 months ago
    Total: 473s
    #215386
  • Pipeline finished with Failed
    4 months ago
    Total: 161s
    #216190
  • Pipeline finished with Success
    4 months ago
    #216191
  • Status changed to Needs review 4 months ago
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    This will need a change record for the new dependency, but I'm not creating one right now until this is reviewed.

  • Status changed to Needs work 4 months ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review 4 months ago
  • πŸ‡¦πŸ‡ΊAustralia mstrelan
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    So not sure the process to evaluate this but looking at https://github.com/symfony/polyfill-php84

    These are functions it claims to introduce

    mb_ucfirst and mb_lcfirst
    array_find, array_find_key, array_any and array_all
    Deprecated
    

    I don't see any open issues
    Last release was June 19th, 2024 so still seems to be active

    I personally don't see any downside,

    Is there a way to identify other places this could be used? Looking at the file in the MR core/lib/Drupal/Component/Assertion/Inspector.php definitely seems cleaner

    I'm a +1

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    If it helps for evaluation we already have a number of symfony polyfills and 10.3.x has symfony/polyfill-php83.

    Is there a way to identify other places this could be used?

    I didn't find an existing rector rule for this, the best I could come up with is so grep for foreach or for loops that have a return statement. If they are returning TRUE or FALSE then they might be candidates for array_all or array_any. If they return something else then possibly could be a candidate for array_find. I don't think it's worth trying to include too much in the initial scope.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    No sure who can make the call though.

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Adding a backend dependency requires release and framework manager signoff.

    Since this is a symphony package and we've used their polyfills before, it does not require a full dependency evaluation.

    I'm personally in favor of the addition.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Yeah makes sense to me too - we can drop the polyfill once we require PHP 8.4, but we get the benefit of the new functions faster.

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Added a change record, assuming it's too late for 11.0.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Think this can be RTBC? @mstrelan mind rebasing and I don't mind marking

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Rebased / reran the composer commands

  • Pipeline finished with Success
    3 months ago
    Total: 402s
    #238864
  • Status changed to RTBC 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks. Sorry if I’m jumping the gun but have only gotten +1s for this

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    I think @catch and I counts as RM signoff, so untagging.

  • Status changed to Needs work 3 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    +1 from me as FM to the concept

    But needs work because the composer.json in lib/Drupal/Component/Assertion also needs to declare this dependency

  • Status changed to Needs review 3 months ago
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Added the dependency as per #17, but unsure if I've done it correctly as the composer.json says it's partially generated automatically and I couldn't understand the link it points to β†’ .

    I guess we'd have to take care to add the same dependency to any other component that uses these functions.

  • Pipeline finished with Success
    3 months ago
    Total: 469s
    #238905
  • Status changed to RTBC 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Not 100% sure why if a core committer would know?

  • Status changed to Needs work 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States xjm

    I broke this when I committed the pre-11.0.0 dep updates, so it will need to be re-generated.

    Regarding the "why do we need to add the dependency" question: The IS of the issue it was for #3272110: Drupal 9 and 10's Drupal\Component composer.json files are totally out of date β†’ explains the problem a bit better. Basically, before that issue, every component's composer.json was maintained by hand and so we got things like them being marked as version 8.8 when the core version was 9.4, declaring requirements of very old PHP versions that did not match core syntax anymore, etc. So the issue added ComponentGenerator, which does things like make the core versions match and reconcile the PHP requirement.

    However, ComponentGenerator is not psychic; it can't tell that we're using PHP 8.4 syntax in this component now when core's own PHP requirement (and therefore all the components' PHP requirements) are 8.3. So to use the PHP 8.4 syntax, the component also needs to declare a direct dependency on the polyfill, in case it's installed by itself without core. Hope that helps. :)

    I do agree that the CR could maybe use some work to be more specific about what ComponentGenerator does (and doesn't do). Also, it would actually be better for the generated message to link permanent documentation (rather than a change record). Let's file a followup to address that.

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Looking at it, there's also a second problem that ComponentGenerator hardcodes PHP 7.3.0, rather than using Drupal's own minimum requirement. So that's a second followup issue needed. (It still would not address the issue of needing the dependency in the component, though.)

  • Status changed to RTBC 3 months ago
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Opened follow ups πŸ“Œ Update package metadata readme to a docs page instead of a change record Active and πŸ› ComponentGenerator hardcodes PHP 7.3.0 Active

    Rebased MR. Setting back to RTBC.

  • Pipeline finished with Success
    3 months ago
    Total: 593s
    #241058
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    The validatable config job failed but that's because it's broken. Opened πŸ› Validatable config job is broken when MR introduces new dependencies Active .

  • Status changed to Needs work 2 months ago
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    I've just realised these array functions won't work on other traversables, only arrays, and that is a regression for the Inspector class.

Production build 0.71.5 2024