|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77290 asXML - fist argument behavior
Submitted: 2018-12-12 18:18 UTC Modified: 2020-03-10 11:00 UTC
From: lagodichyuriy at gmail dot com Assigned: cmb (profile)
Status: Closed Package: SimpleXML related
PHP Version: 7.2.13 OS: Archlinux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: lagodichyuriy at gmail dot com
New email:
PHP Version: OS:


 [2018-12-12 18:18 UTC] lagodichyuriy at gmail dot com
Current asXML() behavior of the SimpleXMLElement object is not really neat: this method may accept "filename" as a first argument for data storing on a HDD. 

However, if a "filename" is empty (let's say "null" or empty string), this method will throw a warning about it.

This logic asks from the programmer create very strange structures to avoid such warning messages: "if ($filename) { return $xml->asXML($filename); } else { return $xml->asXML(); }"

Test script:

function example($file_path = null)
	$xml = new \SimpleXMLElement('<data></data>');

	return $xml->asXML($file_path);


example(); # will throw "PHP Warning:  SimpleXMLElement::asXML(): Filename cannot be empty in ..."

Expected result:
I suggest to make a "filename" as an optional argument for this method.

Actual result:
PHP Warning: SimpleXMLElement::asXML(): Filename cannot be empty in ...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-12 19:26 UTC] Wes dot example at example dot org
I agree with you.
The function implementation must not be aware on whether the argument was filled in automatically or actually specified at call time by developer. Defining behavior depending on whether the argument was explicitly specified or not is just terrible. Unfortunately this happens everywhere in PHP, it's not just this function
 [2020-03-10 11:00 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-03-10 11:00 UTC]
This feature request is already implemented in the master branch[1].

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 08:01:28 2024 UTC