[wp-trac] [WordPress Trac] #29204: SimplePie non-static WP_Feed_Cache::create error in fetch_feed()
WordPress Trac
noreply at wordpress.org
Wed Nov 11 23:46:37 UTC 2020
#29204: SimplePie non-static WP_Feed_Cache::create error in fetch_feed()
------------------------------+-----------------------------
Reporter: useStrict | Owner: SergeyBiryukov
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: 5.6
Component: Feeds | Version: 3.8
Severity: normal | Resolution:
Keywords: has-patch commit | Focuses:
------------------------------+-----------------------------
Comment (by SergeyBiryukov):
For reference, here is a minimal snippet to reproduce the issue in
question:
{{{
class My_Test_Class {
public function create() {
}
}
call_user_func( array( 'My_Test_Class', 'create' ) );
}}}
As noted in comment:19 and seen in [https://3v4l.org/VWcZa test runs],
this causes different results in different versions of PHP:
* `E_STRICT` notice in PHP 5:[[BR]]
`Strict Standards: call_user_func() expects parameter 1 to be a valid
callback, non-static method My_Test_Class::create() should not be called
statically`
* `E_DEPRECATED` notice in PHP 7:[[BR]]
`Deprecated: Non-static method My_Test_Class::create() should not be
called statically`
* A fatal error in PHP 8:[[BR]]
`Uncaught TypeError: call_user_func(): Argument #1 ($function) must be a
valid callback, non-static method My_Test_Class::create() cannot be called
statically`
In case of SimplePie, this is a bit tricky to reproduce, because the
affected [source:tags/5.5.3/src/wp-
includes/SimplePie/Registry.php?marks=214#L205 call_user_func_array()
call] is silenced with the `@` operator, but it becomes more obvious with
the fatal error in PHP 8.
This appears to be a long-standing issue in SimplePie back from 1.2.x
versions.
Some history on the related changes:
* [21644] / #21183 updated SimplePie to 1.3, including marking both
`SimplePie_Cache::create()` and `WP_Feed_Cache::create()` as `static`.
* [21652] / #21183 briefly used a newer approach to register the cache
handler in the same way as suggested in [attachment:"29204.diff"]. Per
[https://simplepie.org/wiki/1.3/caching SimplePie documentation],
registering a cache handler is indeed the recommended approach for
SimplePie 1.3 or later, overriding the `SimplePie_Cache` class is no
longer needed.
* SimplePie 1.3.1 included a
[https://github.com/simplepie/simplepie/commit/9aa3385b315bf0831edaef4815ad8d9317690974
commit] that reverted the addition of `static` keyword for
`SimplePie_Cache::create()` and introduced the
`SimplePie_Cache::get_handler()` method instead.
* [22366] / #22321 updated SimplePie to 1.3.1 in core.
* [22599] / #22321 removed the compatibility code added in [21652], see
comment:11:ticket:22321 for the reasoning. The concern was that plugins
could include earlier versions, so the legacy approach seemed good enough
at the time, but did not account for the silenced notices that became more
severe in later PHP versions and now result in a fatal error on PHP 8.
Looking at [attachment:"29204.3.diff"], it combines both approaches
suggested here earlier, which seems a bit redundant:
* Changing `WP_Feed_Cache` to no longer depend on `SimplePie_Cache`, in
order to add the `static` keyword. Since that is a legacy method that
should have only been used for SimplePie 1.2 or earlier, I don't think
that is the correct path to take here. The whole `class-wp-feed-cache.php`
file should be deprecated instead.
* Registering and using a cache handler, as suggested in
[attachment:"29204.diff"]. I believe that is the way to go here.
In [attachment:"29204.4.diff"]:
* Use the recommended approach of registering a cache handler from
[https://simplepie.org/wiki/1.3/caching SimplePie documentation].
* Mark the `wp-includes/class-wp-feed-cache.php` file as deprecated.
* Add a back-compat check to avoid a fatal error in case there are still
plugins out there including SimplePie 1.2.x.
* Tested on PHP 8.0.0RC4, 7.4.12, and 5.6.40.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29204#comment:55>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list