PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
AGISB
Forum Contributor
Posts: 422 Joined: Fri Jul 09, 2004 1:23 am
Post
by AGISB » Tue Mar 01, 2005 3:50 am
Following problem. I want to call an object and want to return 3 values.
php manual states to return an array so I do something like this in calculate funtion in the class.
Code: Select all
$value1 = 3.14;
$value2 = "This is a value";
$value3 = 1;
return array($value1, $value2, $value3);
So I call the object
Code: Select all
list ($val1, $val2, $val3) = $var->calculate();
when I echo out $val1, $val2 and $val3 they are empty allthough they should have values.
Any advice?
Last edited by
AGISB on Tue Mar 01, 2005 4:50 am, edited 2 times in total.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Tue Mar 01, 2005 4:18 am
Code: Select all
$value1 = 3.14;
$value2 = "This is a value" //<--- This line is missing a semicolon
$value3 = 1;
return array($value1, $value2, $value3);
Add the semicolon and then try. It is working after this.
AGISB
Forum Contributor
Posts: 422 Joined: Fri Jul 09, 2004 1:23 am
Post
by AGISB » Tue Mar 01, 2005 4:23 am
Nah this was just an example so I don't have to publish the big object
This error would show immideately on execution so its just a topic typo
AGISB
Forum Contributor
Posts: 422 Joined: Fri Jul 09, 2004 1:23 am
Post
by AGISB » Tue Mar 01, 2005 4:49 am
Never mind. This was a stupid call problem.
Above code works
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Tue Mar 01, 2005 4:50 am
try printing out the array just before return so that you know they are passing through. then see where the problem is.
EDIT: uh oh...beaten