[wp-trac] [WordPress Trac] #51525: Add new functions apply_filters_typesafe() and apply_filters_ref_array_typesafe()

WordPress Trac noreply at wordpress.org
Thu Oct 15 15:45:21 UTC 2020


#51525: Add new functions apply_filters_typesafe() and
apply_filters_ref_array_typesafe()
------------------------------------------+---------------------
 Reporter:  jrf                           |       Owner:  (none)
     Type:  feature request               |      Status:  new
 Priority:  normal                        |   Milestone:  5.6
Component:  General                       |     Version:  trunk
 Severity:  normal                        |  Resolution:
 Keywords:  2nd-opinion needs-patch php8  |     Focuses:
------------------------------------------+---------------------

Comment (by TimothyBlynJacobs):

 This is super necessary, I'd love to see it happen. I had a couple of
 questions about the implementation.

 > At the start of the function, the variable type of the second parameter
 (the value being filtered) received is checked and remembered. In the loop
 which calls the hooked in functions, a check is done on the variable type
 received back from each function and if it doesn't match the expected
 variable type

 How is the type check going to work?

 Are we going to allow subclasses?

 If the requirement is that a class implement an interface, how will that
 work they might not share a common base class?

 What about places where we want union types?

 What if a plugin allows for `null` to disable the object? How will we
 notate that?

 How strict will the type checking be? If I filtered a `float`, will a
 plugin be able to provide an `integer`?

 I'm sure we can probably have some reasonable defaults. But I think this
 API will really need to support accepting a `check` parameter. This would
 still be a benefit over checking the return type manually because it means
 we won't throwaway the entire filter stack, just the plugin that is
 broken, and of course is simpler DUX wise.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51525#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list