Forum Moderators: coopster

Message Too Old, No Replies

interpolation of object values in strings

easy question I think

         

pixeltierra

8:53 am on Nov 10, 2006 (gmt 0)

10+ Year Member



I have the following:

echo "some text here $this->parent_form->values[$this->name]";

But the object reference isn't interpolated, instead it prints:
"some text here Object->values[name_1]"

however this works:

$value = $this->parent_form->values[$this->name];
echo "some text here $value";

I'n not a OO php wiz or anything, so this could be a stupid question... why doesn't the firt example work?

eelixduppy

2:34 pm on Nov 10, 2006 (gmt 0)



Something like this should work:

echo "some text here {$this->parent_form->values[$this->name]}";

I always take my variables out of the string just to be sure. In this case, it isn't any nicer to have it in the string.

Good luck!

pixeltierra

6:28 pm on Nov 10, 2006 (gmt 0)

10+ Year Member



I thought I tried that and it didn't work. I'll give another go.

Oddly a more simple object reference doesn't seem to require brackets:

echo "hi $this->world";

Works just fine.

eelixduppy

6:31 pm on Nov 10, 2006 (gmt 0)



I think it's because you are using an array: values[$this->name]

These either must be within brackets or taken out of the quotes.

More info [us2.php.net]