chaos83 Posted October 19, 2009 Share Posted October 19, 2009 Hi, I have a bit of experience with PHP but not extensive. It seems I cannot store any items to the array $details. The class: class Newsletter { public $details = array(); function Newsletter($id) { $details['id'] = $id; echo "From same function: " . $details['id']; $this->Load(); } function Load() { echo "From sibling function: " . $details['id']; } } The call from the webpage: $x = new Newsletter(123); //output From same function: 123 From sibling function: Is there a special way to interact with the array so that it sticks for use with other functions? Thanks Link to comment https://forums.phpfreaks.com/topic/178168-array-becomes-unset-by-itself/ Share on other sites More sharing options...
Philip Posted October 19, 2009 Share Posted October 19, 2009 You have a scope problem. To call the one you created class Newsletter { public $details = array(); function Newsletter($id) { $this->details['id'] = $id; echo "From same function: " . $this->details['id']; $this->Load(); } function Load() { echo "From sibling function: " . $this->details['id']; } } Link to comment https://forums.phpfreaks.com/topic/178168-array-becomes-unset-by-itself/#findComment-939435 Share on other sites More sharing options...
chaos83 Posted October 19, 2009 Author Share Posted October 19, 2009 Thank you, you are right Link to comment https://forums.phpfreaks.com/topic/178168-array-becomes-unset-by-itself/#findComment-939440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.