Jump to content

Using a variable in calling a class variable and from outside a class method


scrubbicus

Recommended Posts

What I'm trying to do is using a variable in calling a variable from the inside and a method from the outside but it's not working.

 

Inside the class I'm doing this

 

$this->_$table

 

Outside I'm trying to call

 

$display->$table();

You don't need the $ signs after the ->

It's not required.

 

But $display->table() is called a function. $this->_table would be a variable, so there shouldn't be any problem if your just trying to run the function table() inside the class and inside the class you call the variable $this->_table

 

Please explain your problem more, including any errors that might be appearing.

Well for instance I have a method inside my class that's something like this

 

public function getForm($table) {

$results = mysql_query('SHOW COLUMNS FROM '.$table.'');

while($row = mysql_fetch_array($results)) {

if($row[0] != 'id') {

$this->_table_$table[] = $row[0];

}

}

return $this->_table_$table;

}

 

You see $this->_table_$table, when I call the method from outside the class I'm putting a value in their and I want that value to pass down into that variable. So if my value is 'client' it'll set the variable $this->_table_client and return that value as well, if I set my value to 'content' I want it to instead set the variable $this->_table_content.

 

I can't find where this is in my code but I'm sure I'll come across it. Another thing is if I have multiple methods inside my class like public function client() and public function content() outside my class I have something like this:

 

$display->$table

OR

$display->$_GET['section'];

 

So it's dynamic what it calls (the $table would be set to either 'client' or 'content'.

 

Also

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.