|
|
Question : PHP class function call
|
|
----I have a php class:
class Table {
var $name, $postion;
function Table($name, $postion){
$this->name = $name; $this->postion = $postion; }
function getName(){ return $this->name; }
function getPostion(){ return $this->postion; }
}
----and have a array with the class objects
function table_info(){ $table_info[0] = new Table("location",0); $table_info[1] = new Table("competition",1); $table_info[2] = new Table("design",2); $table_info[3] = new Table("economic_conditions",3); $table_info[4] = new Table("projections",4); $table_info[5] = new Table("restaurant",5); $table_info[6] = new Table("service",6); $table_info[7] = new Table("floor",7); $table_info[8] = new Table("bar",8); $table_info[9] = new Table("submit",9); return $table_info; }
-----And am trying to return the a Table objects name, with getName() in the table class
$table_info=table_info(); echo getName($table_info[1]));
----The output is an error messege: undefined function getName().
|
Answer : PHP class function call
|
|
You have to write as following: $table_info=table_info(); echo $table_info[1]->getName();
|
|
|
|
|