#37122 closed defect (bug) (fixed)
Error out when xml_create_parser is not available
Reported by: | kraftbj | Owned by: | pento |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | XML-RPC | Keywords: | has-patch |
Focuses: | Cc: |
Description
When PHP XML is not available, we fatal with an PHP Fatal error: Call to undefined function xml_parser_create()
in wp-includes/class-IXR.php
and other files.
We already error out when that function is not available in wp-includes/rss.php
since [3083].
Background: The PHP 7 packages on Ubuntu, unlike PHP 5, does not include php7.0-xml
by default, so there may be an increase in failures of this type as folks switch over.
Attachments (4)
Change History (23)
This ticket was mentioned in Slack in #core by kraft. View the logs.
8 years ago
#4
@
8 years ago
- Keywords has-patch added; needs-patch removed
Attached a patch. SimplePie appears to check for the xml extension directly before running, which likely covers it.
#7
@
8 years ago
- Keywords needs-refresh added; has-patch commit removed
The check before the solitary call to xml_parser_create_ns()
is a check for xml_parser_create()
. While presumably the former will be available when the latter is also available, why not actually check for the function that's about to be called?
For the cases when duplicate code is created (check + call to xml_parser_create()
), I think it may make more sense to add in a wp_xml_parser_create()
that can handle this in a cleaner way. i.e.
function wp_xml_parser_create( $encoding = null ) {
if ( ! function_exists( 'xml_parser_create' ) ) {
trigger_error( __( 'The XML extension for PHP is not available. Please contact your hosting provider to enable it." ) );
}
return xml_parser_create( $encoding );
}
Then use wp_xml_parser_create()
in the instances where non-library code in WP currently uses xml_parser_create()
.
Regardless of my suggestion, I think the patch needs a refresh, as some files have been moved around.
#8
@
8 years ago
Good call wrt xml_parser_create_ns
. I'm neutral on the helper function. I'm about to hit the road, but can refresh it later this week.
#9
@
8 years ago
- Keywords has-patch added; needs-refresh removed
I have uploaded a new patch that fixes the check for xml_parser_create_ns
but mainly fixed the problem with previous code and first patch is still you still need to return something otherwise it's still fatal errors.
This ticket was mentioned in Slack in #core by stevenkword. View the logs.
8 years ago
#12
@
8 years ago
I updated the patch some:
- src/wp-admin/link-parse-opml.php -- I kill processing using wp_die instead of the if/else structure. This file isn't called by Core, seemingly only called by the OPML Importer plugins (perhaps others).
- src/wp-includes/feed.php - Confirming that the given return makes enough sense. We aren't able to confirm it is XML, so returning as a looser type should be fine.
prep_atom_text_construct()
doesn't seem to be called by Core either. - src/wp-includes/rss.php - I updated the error messages to be consistent with the others (and the php.net link isn't helpful for the PHP 7 issue). Previously, it called the parser while suppressing errors, then checking if it is a php resource. Changed it to be consistent with the other checks.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
#15
@
8 years ago
Looks good to me but haven't been able to test it on my end as this fixes edge cases (removed functionality)
#19
in reply to:
↑ description
@
8 years ago
Replying to kraftbj:
When PHP XML is not available, we fatal with an
PHP Fatal error: Call to undefined function xml_parser_create()
inwp-includes/class-IXR.php
and other files.
We already error out when that function is not available in
wp-includes/rss.php
since [3083].
Background: The PHP 7 packages on Ubuntu, unlike PHP 5, does not include
php7.0-xml
by default, so there may be an increase in failures of this type as folks switch over.
We use that function in the following files, seemingly without a check at first glance:
/wp-admin/link-parse-opml.php
(long live Links)/wp-includes/atomlib.php
/wp-includes/class-simplepie.php
/wp-includes/feed.php
/wp-includes/SimplePie/Parser.php
and a couple of unit tests.