PHP Calling class method from constructor not filling array
<p>I have a very weird problem that when I call the method of a class from within the constructor I get as a result empty arrays, but when I call the method from the class instance it works fine.</p>

<p>Here is the code for loadxml.php:</p>

<pre><code>include('XMLNode.php'); // this is a simple object class

class LoadXML
{
public $MyNodes = array();

public function __constructor($xmlFile)
{
    $this-&gt;getNodes($xmlFile);
}

public function getNodes($xmlFile)
{
    if (file_exists($xmlFile)) {
        $xmlNodes = simplexml_load_file($xmlFile);

        foreach ($xmlNodes-&gt;XMLNode as $key =&gt; $value) {
            array_push($this-&gt;MyNodes, $value);
        }
    }
    else
    {
        exit('Failed to open xml file '.$xmlFile);
    }
}
}
</code></pre>

<p>Now in the main file if I make the call like this:</p>

<pre><code>include('loadxml.php');

$nodes = new LoadXML('myXMLFile.xml');

print "&lt;pre&gt;";
print_r($nodes);
print "&lt;/pre&gt;";
</code></pre>

<p>... the result looks like this:</p>

<p>LoadXML Object
(
    [MyNodes] => Array
        (
        )
)</p>

<p>If I make the call from the class instance like this and comment out the call to getNodes from the LoadXML constructor:</p>

<pre><code>include('loadxml.php');

$nodes = new LoadXML();
$nodes-&gt;getNodes('myXMLFile.xml');

print "&lt;pre&gt;";
print_r($nodes);
print "&lt;/pre&gt;";
</code></pre>

<p>I will get the correct output. What's happening? What am I doing wrong in the first approach? Am I missing something from the class constructor? I looked in the manual (<a href="http://php.net/manual/en/oop4.newref.php" rel="nofollow">http://php.net/manual/en/oop4.newref.php</a>) and the call to the method seems legit from within the constructor.</p>
