class BetterDOMDocument extends DOMDocument
{
function __construct($version = null, $encoding = null) {
parent::__construct($version, $encoding);
}
}
This code will generate an XML header with an empty version attribute.
However, I cannot just define the constructor as:
function __construct($version, $encoding) {}
Because now PHP complains about Undefined Variable usage if I want to use this constructor without passing any arguments.
DOMDocument
does not require be to passed $version
, it'll use a default if I don't pass a value. How can I override the constructor while keeping the argument handling of the base class unchanged, without duplicating the specific default values?
I'm interested in this not in terms of a problem I'm stuck at that needs a workaround, but in terms of PHP language design. Can one , and how so, reproduce the behavior of DOMDocument in PHP, or is there something special about how internal code is able to deal with undefined values?