PHP constructor not populating properties

3puppies
3puppies used Ask the Experts™
on
The main goal of the constructor is for the calling script to specify values to prepopulate two of the properties in the class.  The class starts as follows:

class printRecord {
      public $html = "";
      public $identifier = 0;
      public $scoreType = "";
      public $tests = array();
      public $person = array();
      
      function __constructor($pid,$st){
            $this->identifier = $pid;
            $this->scoreType = $st;
      }

      public function getScores(){
            switch($this->scoreType){
                  case 'GRE':
                        $this->getGRE();
                        break;
                  case 'TOEFL':
                        $this->getTOEFL();
                        break;
                  default:
                        throw new Exception("printRecord class threw: Invalid score type specification (".$this->scoreType.")");
            }
      }
}

There are obviously other methods associated with this class, they query a MySQL database and get score reports from the GRE and TOEFL score reporter and are also able to reformat the returns into HTML.  

I am trying to make it so that I can pass a person's UID in the database as well as the test as so:

$test = new printRecord(1234,'GRE');

Whenever I instantiate a new object with only the __construct() method defined, the values in the constructor seem not to get populated.  When I call $test->getScores(), it returns "printRecord class threw: Invalid score type specification ()" which says to me that the constructor is either not being called or does not properly populate.  From the documentation that I have read, I am using the constructor correctly, but since it is still not working I have to believe that I am doing something wrong.  What does work is adding the following:

      function printRecord($pid,$st){
            $this->__constructor($pid,$st);
      }

So, the old form of the constructor works, but not the new form.  Is there some sort of setting that I am missing when trying to use the new constructor form?

Thanks for any help.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
What version of PHP are you using?  Get the output of phpinfo() if you don't know.
Commented:
Hi!

You made an mistake, when writing function name: __constructor, it must be __construct

Just replace __constructor($pid,$st) into __construct($pid,$st) and script will shoud work

Author

Commented:
It's always the little things :P

And I am using 5.3.2 for the record.
xSERGE == EagleEye  {gj :-}

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial