[Lunr.Locator] General: Support Union types in get_parameters

Review Request #866 — Created Aug. 25, 2022 and discarded

smillernl
Lunr.Locator
fix/php81/union_types
lunr

General: Support Union types in get_parameters
Also removes a test that checked internal PHP behaviour that changed in PHP 8

Accompanies https://github.com/M2mobi/lunr.locator/pull/3



  • 1
  • 0
  • 2
  • 0
  • 3
Description From Last Updated
Interesting corner case: what if the type is string|object. The string code here would bypass the locator, so we'd never ... pprkut pprkut
smillernl
pprkut
  1. 
      
  2. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 2)
     
     
     
     
     
     
     
     
     

    I'd rather have the foreach extra cost for union types only

    1. That makes sense, how do you feel about allowing Stringable here and above?

    2. I don't think that would be useful. The whole point of checking for string is so we can have literal string arguments in locator recipes without !. We wouldn't have literal "stringables", and objects coming from other locator recipes wouldn't need this. They wouldn't even work, because you can't cast a Stringable to string if it isn't instantiated yet.

  3. 
      
smillernl
b.stoop
  1. 
      
  2. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 3)
     
     
     
     

    Why not use the old if?

  3. 
      
smillernl
pprkut
  1. 
      
  2. src/Lunr/Core/ConfigServiceLocator.php (Diff revision 4)
     
     
     
     
     
     
     
     
     
     
     
     

    Interesting corner case: what if the type is string|object. The string code here would bypass the locator, so we'd never be able to pass an object instance.

    1. You should design your code better? :)
      We could also just skip this case to avoid ambiguity

  3. 
      
smillernl
Review request changed

Status: Discarded

Change Summary:

Union type support is too ambiguous. It should just use the !string syntax

Loading...