Object return value[solved]

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

Post Reply
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Object return value[solved]

Post by AGISB »

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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

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 »

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 »

Never mind. This was a stupid call problem.

Above code works
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

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 :)
Post Reply