Jump to content

returning an array?


ChrisMartino

Recommended Posts

Hey there,

 

Now I was curious if there was a way I could return an array in my function like the following, I currently get a error though:

 

Catchable fatal error: Object of class panel_accounts could not be converted to string in C:\wamp\www\X-HostLTD - Panel\PanelFrontend\index.php on line 21

 

But can you only return strings?.

 

Here is the function that it errors on:

 

function returnAccountInformation($AccountID)
{
return mysql_fetch_array(mysql_query("SELECT * FROM ****_***** WHERE *****_***** = '".mysql_escape_string($AccountID)."'"));
}

 

Could somebody help me on the matter?, Thank you.

 

P.S sorry for staring out the table names but I don't really want people knowing my database structure :P hehe.

Link to comment
https://forums.phpfreaks.com/topic/209542-returning-an-array/
Share on other sites

The problem is that you're trying to convert an object to a string, likely doing so implicitly by trying to echo or print it.

 

Objects that do not have a __toString method do not have any defined mechanism for being converted to a string and as such throw an exception like that one.

 

 

 

I need to see more code before I can help you with actual code though.  That function you posted does not return an object.

Link to comment
https://forums.phpfreaks.com/topic/209542-returning-an-array/#findComment-1093974
Share on other sites

The problem is that you're trying to convert an object to a string, likely doing so implicitly by trying to echo or print it.

 

Objects that do not have a __toString method do not have any defined mechanism for being converted to a string and as such throw an exception like that one.

 

 

 

I need to see more code before I can help you with actual code though.  That function you posted does not return an object.

 

Thanks for your help, It was a mistype error that caused it, in the functions arguments I put two $'s for the variable, and AlexWD thanks for telling me!, I've just converted them all over now.

Link to comment
https://forums.phpfreaks.com/topic/209542-returning-an-array/#findComment-1094055
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.