Jump to content

echo $class->string; reserved/function names?


Marco000

Recommended Posts

First of apologies for any inconvenience if this has been posted before as I’m unsure of what it could possibly be called/come under besides something like "reserved variables"?

 

I have a class that pulls a result out of a database and loads them into class variables by the database field name like the following

 

// Load the results into the class
foreach ($array as $name => $value) {
$this->$name = $value;
}

 

This works fine as expected but the problem occurs when I try to echo one of the fields names in the database (it’s called "string") It ends up being like echo $advert->string; and it’s not outputting anything? In Dreamweaver its showing the class variable "string" as a different colour so I’m guessing something isn’t right in terms of "string" being reserved or a function?

 

How could I get the final/desired output/action I’m looking for here as I’m completely stumped! I normally Google for my solutions but have no idea what I have come across is called.

 

PS. Sorry for anything I do wrong, just signed up and don’t know the ropes yet in terms of acceptable behaviour, community expectations and ways to post queries.

Link to comment
Share on other sites

But that means i might aswell change the field name in the database as it acomplishs the same thing?

 

also is there a list of reserved variable names? to look over to increase my knowledge of this? I notice this happens with "int" too (echo $object->int)

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.