peachpie
peachpie copied to clipboard
Error in constructor of class inheriting DOMDocument?
Peachpie.Library.XmlDom test of php.
<?php
class Class1 extends DOMDocument{
public function __construct($file){
parent::__construct();
if(file_exists($file)) $this->load($file);
}
}
$xml_filename="./abc.xml"; // The content of abc.xml is: <root>abc</root>
$obj1=new Class1($xml_filename);
call this class error: Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. In Peachpie, both file_exists and load will go wrong?
Do you have a full call stack?
There seems to be no context support in __construct() in this Class1 subclass?
Source code file | https://github.com/peachpiecompiler/peachpie/blob/master/src/Peachpie.Library.XmlDom/DOMDocument.cs Constructor definition in the source file: Line 275:
public DOMDocument(string version = null, string encoding = null)
Should it be like this ?:
public DOMDocument(Context ctx, string version = null, string encoding = null)
This problem can be solved in a php script, but it's not elegant!
<?php
class xmldom extends DOMDocument{
public static function get_instance($file){
$o=new xmldom();
if(file_exists($file)) $o->load($file);
return $o;
}
public function __construct(){
parent::__construct();
}
}
$xml_filename="./abc.xml"; // The content of abc.xml is: <root>abc</root>
$obj1=xmldom::get_instance($xml_filename);
hi @wujwmail ! Thank you very much for reporting the issue.
It is a bug in our implementation of DOMDocument. I'll take a look how to fix it.