Jump to content

Array becomes unset by itself?


chaos83

Recommended Posts

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

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'];
}
}

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.