3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class XmlHelper extends SimpleXMLElement { /** * @param string $name * @param float|int|string $value * @param null|string $namespace * @param null|int|string $maxlength * * @return static */ public function addChild($name, $value = null, $namespace = null, $maxlength = null) { if ($maxlength) { $value = substr((string)$value, 0, (int)$maxlength); } return parent::addChild($name, (string)$value, $namespace); } } $xml = new XmlHelper( '<DISPATCHNOTIFICATION version="2.1" xmlns="http://www.opentrans.org/XMLSchema/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opentrans.org/XMLSchema/2.1 opentrans_2_1.xsd" xmlns:bmecat="http://www.bmecat.org/bmecat/2005" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"> </DISPATCHNOTIFICATION>' ); $DISPATCHNOTIFICATION_HEADER = $xml->addChild('DISPATCHNOTIFICATION_HEADER'); var_dump($DISPATCHNOTIFICATION_HEADER, $xml->saveXML());
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Deprecated: Return type of XmlHelper::addChild($name, $value = null, $namespace = null, $maxlength = null) should either be compatible with SimpleXMLElement::addChild(string $qualifiedName, ?string $value = null, ?string $namespace = null): ?SimpleXMLElement, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/USJWu on line 13 object(XmlHelper)#2 (0) { } string(409) "<?xml version="1.0"?> <DISPATCHNOTIFICATION xmlns="http://www.opentrans.org/XMLSchema/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bmecat="http://www.bmecat.org/bmecat/2005" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" version="2.1" xsi:schemaLocation="http://www.opentrans.org/XMLSchema/2.1 opentrans_2_1.xsd"> <DISPATCHNOTIFICATION_HEADER/></DISPATCHNOTIFICATION> "
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Return type of XmlHelper::addChild($name, $value = null, $namespace = null, $maxlength = null) should either be compatible with SimpleXMLElement::addChild(string $qualifiedName, ?string $value = null, ?string $namespace = null): ?SimpleXMLElement, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/USJWu on line 13 object(XmlHelper)#2 (0) { } string(409) "<?xml version="1.0"?> <DISPATCHNOTIFICATION xmlns="http://www.opentrans.org/XMLSchema/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bmecat="http://www.bmecat.org/bmecat/2005" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" version="2.1" xsi:schemaLocation="http://www.opentrans.org/XMLSchema/2.1 opentrans_2_1.xsd"> <DISPATCHNOTIFICATION_HEADER/></DISPATCHNOTIFICATION> "
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
object(XmlHelper)#2 (0) { } string(409) "<?xml version="1.0"?> <DISPATCHNOTIFICATION xmlns="http://www.opentrans.org/XMLSchema/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bmecat="http://www.bmecat.org/bmecat/2005" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" version="2.1" xsi:schemaLocation="http://www.opentrans.org/XMLSchema/2.1 opentrans_2_1.xsd"> <DISPATCHNOTIFICATION_HEADER/></DISPATCHNOTIFICATION> "

preferences:
109.38 ms | 403 KiB | 158 Q