But I know the function is in there!
Consider the following code:
<?php
class parentClass {
var $x;
var $child;
function parentClass($_x, $_child) {
$this->x = $_x;
$this->child = $_child;
$this->child->m = "Grow up, son<br>";
}
function foo() {
return "I'm the parent.<br>";
}
}
class childClass {
var $m;
function childClass($_m) {
$this->m = $_m;
}
function goo(){
return "I'm the child.<br>";
}
}
$son = new childClass("I want my mommy<br>");
$dad = new parentClass("I want a new Porche<br>", $son);
echo $dad->child->goo();
echo $dad->child->m;
echo $son->m;
?>
// the output is
I'm the child.
Grow up, son
I want my mommy
My question is:
Where do I put the & operator so that I pass a reference instead of a copy
-- so the output will be
I'm the child.
Grow up, son.
Grow up, son.
I've tried everywhere I can think of to pass a reference instead of a copy
and it doesn't error and doesn't pass a reference. I always pass a copy,
even when I use multiple &'s all over the place.
If I can get this simplest of examples working, and then fail to get my code
working in my previous post, I'll paste it for your guidance & suggestions.
TIA-
Geoff
-----Original Message-----
From: Ernest E Vogelsinger [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 27, 2002 7:06 AM
To: Hoffman, Geoffrey
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] object passing by reference
At 01:34 27.11.2002, Hoffman, Geoffrey spoke out and said:
--------------------[snip]--------------------
>I want to pass a reference to objectA along with other strings to a new
>objectB( constructor.
>
>Where does my & go? I just keep getting
>
>Fatal error: Call to a member function on a non-object
--------------------[snip]--------------------
Just as the error message says - you're trying to execute a function
(like $hObj->foo()) where there's no such function.
Would be helpful if you posted some code where the error arises...
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php