Jump to content

class problem in php4


peeper

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.