scrubbicus Posted April 30, 2009 Share Posted April 30, 2009 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(); Link to comment https://forums.phpfreaks.com/topic/156330-using-a-variable-in-calling-a-class-variable-and-from-outside-a-class-method/ Share on other sites More sharing options...
JasonLewis Posted May 1, 2009 Share Posted May 1, 2009 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. Link to comment https://forums.phpfreaks.com/topic/156330-using-a-variable-in-calling-a-class-variable-and-from-outside-a-class-method/#findComment-823195 Share on other sites More sharing options...
scrubbicus Posted May 1, 2009 Author Share Posted May 1, 2009 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 Link to comment https://forums.phpfreaks.com/topic/156330-using-a-variable-in-calling-a-class-variable-and-from-outside-a-class-method/#findComment-823219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.