0

my problem is in PHP.. I have an object location with attributes name,date,address and get and set methods... class location{ public $name; public $date; public $address; public function set_name($myname){ $this->name=$myname; } public function get_name(){ return $this->name; } } Then i created an array $locations_array=array();

i also created an instance of the class location:

$my_loc=new location;
$my_loc->set_name("africa");
$locations_array[0]=$my_loc;
echo $locations_array[0]->get_name();

when i try to echo the name of the object $my_loc..there's an error..how can i remedy this?

0

1 Answer 1

1

I tried this in an interactive PHP shell and everything worked fine. It must be some kind of error specific to your computer, either that or a typo.

And you might want to reconsider even the existence of the set_name and get_name functions if the name property is public anyway.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much..i think i made a small error...i forgot to add the "$" before a variable..that's why it wasn't getting the data...
Yeah, I've made errors like that all the time. No worries. It really stinks when you're missing one semicolon in like a hundred lines of code. XD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.