Hi I'm currently programming what will eventually be a fully automated site for a computer gaming league, and I was having a problem with taking an array in and assigning it as a variable in a class. I'm a past C++ programmer, and I really havn't used PHP *that* much, so I'm just wondering if there's a quirky language problem I don't know about. I'm so against stealing scripts I won't even take a news system without knowing exactly what happens.
class newspost
{
var $poster;
var $timestamp;
var $title;
var $content=array(null);
function set($poster, $timestamp, $title, $content)
//This function sets this newspost to the input values
{
$this->poster=$poster;
$this->timestamp=$timestamp;
$this->title=$title;
$this->content=$content;
//for ($i=0;$i<count($content);$i++)
//$this->content[$i]=$content[$i];
echo "$content[0]";
echo "$this->content[0]";
}
//... couple more functions
}
Basically what happens is the array inside the class ($this->content) isn't set to what the input array is ($content). I've tried multiple ways of assigning it, including array_slice and that 'for' loop, but they all do the same thing, which is nothing. The first test echo outputs the correct value, but the second one just puts: Array[0]
Also, "var $content=array(null);" is only like that because I was testing if an array had to be declared as an array in the class. Neither that nor "var $content;" work.
class newspost
{
var $poster;
var $timestamp;
var $title;
var $content=array(null);
function set($poster, $timestamp, $title, $content)
//This function sets this newspost to the input values
{
$this->poster=$poster;
$this->timestamp=$timestamp;
$this->title=$title;
$this->content=$content;
//for ($i=0;$i<count($content);$i++)
//$this->content[$i]=$content[$i];
echo "$content[0]";
echo "$this->content[0]";
}
//... couple more functions
}
Basically what happens is the array inside the class ($this->content) isn't set to what the input array is ($content). I've tried multiple ways of assigning it, including array_slice and that 'for' loop, but they all do the same thing, which is nothing. The first test echo outputs the correct value, but the second one just puts: Array[0]
Also, "var $content=array(null);" is only like that because I was testing if an array had to be declared as an array in the class. Neither that nor "var $content;" work.