Re: Variable Overloading or Replacement (long)
| From: | Raditha Dissanayake | Date: | Wed, 10 Sep 2003 14:00:00 +0000 |
| Subject: | Re: Variable Overloading or Replacement (long) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-162172@lists.php.net to get a copy of this message | ||
Hello,
my comments are below this snippet.
------------------------------------------------------------ class AGENT{ /* ** 2003-09-04 jb PRIVATE PROPERTIES */ var $strCommCode; // agent commission code ------------------------------------------------------------ ------------------------------------------------------------ function AGENT(){ // class pseudo-constructor /* ** 2003-09-09 jb initialize properties */ $this->strCommCode = 'COINBASE'; ------------------------------------------------------------ ------------------------------------------------------------ require("agentclass.php"); class COIN extends AGENT { var $strCommCode = 'COIN0JAY'; } /* ** instantiate new COIN object */ $objDime = new COIN(); echo $objDime->strCommCode."\n"; ------------------------------------------------------------ The result of $objDime->strCommCode is 'COINBASE'...my thinking is that it should be 'COIN0JAY' You can get the expected result if you add an empty constructor to your Coin class.ASAIK php does not believe in the concept of default constructors. If a class does not have a constructor it will happily call the constructor in the super class instead and leave it at that. While on the other hand if you have a constructor in your subclass the constructor in the superclass does not get called!. I don't like it either but that's the way it's 'defined to be' in PHP. To sum up your strCommCode in the COIN class does override the strCommCode member in AGENT. But it's value is actually set by the constructor in AGENT and it's not the value that you define at the time of declaration. best regards -- http://www.radinks.com/upload Drag and Drop File Uploader.