peeper Posted January 30, 2007 Share Posted January 30, 2007 Hi,I'm finding problems using classes in php4 (I'm used to strongly typed languages - C++ and Java). Here's a piece of code that roughly demonstrates what I'm trying to do:[code]class A{ function doItToA($aString) { echo($aString); }}class B{ var $a; function B(&$a) { $this->a = $a; } function doItToB($aString) { $this->a->doItToB($aString); }}// ...$a = &new A();$b = new B($a);$b->doItToB("random text here");[/code]Now the problem is that the parameter, "random text here", that I pass into the call $b->doItToB("random text here") doesn't appear to make it's way through to doItToA($aString) - the text "random text here" isn't echoed as I would expect it to.I haven't seen any examples of objects (such as the instance of B, above) being used as member attributes within classes. I expect I don't have a full grasp of on way classes work in PHP. Any guidance on what the problem might would be much appreciated.Thanks,Peeper. Link to comment https://forums.phpfreaks.com/topic/36275-class-problem-in-php4/ Share on other sites More sharing options...
Jenk Posted January 30, 2007 Share Posted January 30, 2007 [code=php:0]$this->a->doItToB($aString);[/code]should be:[code=php:0]$this->a->doItToA($aString);[/code]I also recommened updating to php5, the Object model was greatly refactored. Link to comment https://forums.phpfreaks.com/topic/36275-class-problem-in-php4/#findComment-172506 Share on other sites More sharing options...
peeper Posted January 30, 2007 Author Share Posted January 30, 2007 Thanks for your response, but that doesn't answer my question. The question is primarily one of how to use a member attribute when that attribute is itself a user-defined class. Any further help would be welcome.BTW, the version of PHP is out of my hands. PHP 4 is the only version that is available to me.Thanks,Peeper. Link to comment https://forums.phpfreaks.com/topic/36275-class-problem-in-php4/#findComment-172637 Share on other sites More sharing options...
Jenk Posted January 30, 2007 Share Posted January 30, 2007 If by that you mean fluid transistion (object linking as you have done,) it's not possible in PHP4. It is available in PHP5, though. Link to comment https://forums.phpfreaks.com/topic/36275-class-problem-in-php4/#findComment-172652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.