Req #77290 [Com]: asXML - fist argument behavior

From: Date: Wed, 12 Dec 2018 19:26:51 +0000
Subject: Req #77290 [Com]: asXML - fist argument behavior
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218427@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77290&edit=1 ID: 77290 Comment by: Wes dot example at example dot org Reported by: lagodichyuriy at gmail dot com Summary: asXML - fist argument behavior Status: Open Type: Feature/Change Request Package: SimpleXML related Operating System: Archlinux PHP Version: 7.2.13 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2018-12-12 18:18:25] lagodichyuriy at gmail dot com Description: ------------ 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: --------------- <?php 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 ... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77290&edit=1

« previous php.bugs (#218427) next »