simplexml_load_file

FunctionParams and return types changed in PHP 8.0

Interprets an XML file into an object.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

simplexml_load_file Function synopsis

simplexml_load_file(
    string $filename,
    ?string $class_name = SimpleXMLElement::class,
    int $options = 0,
    string $namespace_or_prefix = "",
    bool $is_prefix = false
  ): SimpleXMLElement|false

Parameters

$filename

Typestring

Path to the XML file

$class_name

OptionalType?stringDefault valueSimpleXMLElement::class

You may use this optional parameter so that simplexml_load_file will return an object of the specified class. That class should extend the SimpleXMLElement class.

$options

OptionalTypeintDefault value0

$namespace_or_prefix

OptionalTypestringDefault value""

Namespace prefix or URI.

$is_prefix

OptionalTypeboolDefault valuefalse

true if $namespace_or_prefix is a prefix, false if it's a URI; defaults to false.

Return value

TypeSimpleXMLElement|false

Returns an object of class SimpleXMLElement with properties containing the data held within the XML document, or false on failure.

Changes to the simplexml_load_file Function

PHP 8.0

  • Return type added: SimpleXMLElement|false
  • Parameter type added for parameter #1 ($filename): string
  • Parameter type added for parameter #2 ($class_name): ?string
  • Parameter default value added for position #2 ($class_name): SimpleXMLElement::class
  • Parameter type added for parameter #3 ($options): int
  • Parameter default value added for position #3 ($options): 0
  • Parameter name of parameter #4 changed: $ns to $namespace_or_prefix
  • Parameter type added for parameter #4 ($namespace_or_prefix): string
  • Parameter default value added for position #4 ($namespace_or_prefix): ""
  • Parameter type added for parameter #5 ($is_prefix): bool
  • Parameter default value added for position #5 ($is_prefix): false
  simplexml_load_file(
-     $filename,
+     string $filename,
-     $class_name,
+     ?string $class_name = SimpleXMLElement::class,
-     $options,
+     int $options = 0,
-     $ns,
+     string $namespace_or_prefix = "",
-     $is_prefix
+     bool $is_prefix = false
-   )
+   ): SimpleXMLElement|false

simplexml_load_file Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes