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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.