Error using print {} and a function
Posted: Thu Oct 18, 2007 7:33 am
scottayy | Please use
Thanks,
e
scottayy | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have some code that doesn't seem to work and i'm not sure why. I tried three different ways of coding it and example 1 and 2 work but the third doesn't.
I get a unexpected ( error from Example 3.
Is it just that I have () enclosed in {} enclosed in a print string? Is there away around this.. It just seems shorter than concatenating.
I have a UnitCounter class with a function called totalWeight that does is a quick calculation of units * weight and return that value. I have assigned weights and unit numbers to the vars.Code: Select all
$b = new UnitCounter;
//Example 1: This works
print "total weight = " . $b->totalWeight() . "kg";
//Example 2: This works
$a = $b->totalWeight();
print "total weight = {$a} kg";
//Example 3: This doesn't work.. why?
print "total weight = {$b->totalWeight()} kg";Thanks,
e
scottayy | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]