PHP 7 simpleXML

PHP 7 simpleXML

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

The SimpleXML Mystery in PHP 7 Builds

Encountering a situation where phpinfo() reports an extension is loaded, yet the corresponding functions remain inaccessible in your code, is a classic case of configuration desynchronization. In the specific scenario described by users upgrading to PHP 7 on Debian-based systems, this behavior stems from how the interpreter initializes extensions versus how they are exposed to the application layer.

The user's observation that phpinfo() displays SimpleXML while function_exists('simplexml_load_file') returns false indicates a fundamental mismatch between the loaded modules and the active configuration directives. The provided output confirms that PHP 7.0.3 is running, likely built from source or via a specific repository (deb.sury.org~trusty+2). In many standard distributions, extensions compiled into the core are automatically available. However, when dealing with third-party repositories or custom builds, the distinction between "compiled in" and "loaded via configuration" becomes critical.

The missing entry in the php -m output is the smoking gun. Even if the extension library files exist within the installation directory, PHP will not load them unless explicitly told to do so by a directive in the configuration file. The presence of the extension name in phpinfo() can sometimes be misleading if the script is loading an older version of the info page cache or if the check logic relies on internal flags that differ from the module loader's state. More commonly, however, this specific symptom suggests that the extension was compiled but not included in the runtime list because the extension directive is absent or commented out.

To resolve this without rebuilding the entire PHP binary, you must inspect the active configuration files. The primary culprit is almost always php.ini. Look for a line resembling:

;extension=simplexml.so

In PHP 7, if this line is commented out (prefixed with a semicolon), the extension will not be loaded into the runtime environment, regardless of whether it appears in static diagnostic output or if the library file exists. You need to uncomment this line and save the file:

extension=simplexml.so

After making this change, you must restart the PHP service (e.g., Apache, Nginx with PHP-FPM, or CLI) for the configuration to take effect. If you are managing a custom SCL (Software Collections) environment like the one hinted at by the sury.org repository path, ensure that your .ini files reside in the correct directory and that the service reloads the new settings.

There is also a possibility that the extension was compiled without enabling the SimpleXML module during the build process, or that the specific version of PHP 7 being used has deprecated certain aspects of SimpleXML in favor of DOMDocument or native string manipulation for performance reasons. While SimpleXML is part of the standard library, some stripped-down builds remove it to reduce memory footprint or dependency chains. In such cases, checking the source code used to compile the binary (configure --help) would reveal if --enable-simplexml was passed.

If you cannot modify the configuration file directly, you can force PHP to load extensions by passing them via the command line for CLI scripts:

php -d extension=simplexml.so your_script.php

This approach bypasses the need to edit system-wide configuration files and is useful for quick testing or containerized environments where persistence isn't required. However, for production web applications, modifying php.ini remains the most robust solution.

Remember that relying solely on phpinfo() can be dangerous when debugging extension issues. Always verify availability using runtime checks like function_exists() within your application logic. If you are developing a Laravel application or similar framework, ensure your composer.json does not inadvertently conflict with required extensions, though SimpleXML is rarely a Composer dependency since it is built-in.

For developers maintaining legacy systems on older distributions like Trusty (as suggested by the repository path), upgrading PHP versions often resolves these inconsistencies, as newer builds tend to have stricter module loading defaults. If you are migrating away from this specific build, consider switching to a stable release from the official Debian repositories or using Docker images that guarantee consistent extension loading across environments.

Our network