Re: Array inside Class

From: Date: Fri, 10 Sep 2004 18:43:16 +0000
Subject: Re: Array inside Class
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-196335@lists.php.net to get a copy of this message
On Fri, 10 Sep 2004 14:26:22 -0400, John Holmes <holmes072000@charter.net> wrote: > From: "dirk" <dirk.kleinschmidt@gmail.com> > > can anyone explain to me, why I can't resize an array inside a class? > > Sample Code: > > > > <?php > > class Liste { > > var $input = array (1,2,3); > > var $input2 = array_pad ($input,10, 1); > > } > > ?> > > > > Output: > > Parse error: parse error, unexpected '(', expecting ',' or > > ';' in > > /srv/www/htdocs/stundenplan/stpoo.php on line 4 > > You can't assign values like that. > > Try this: > var $input = array(1,2,3); > var $input2 = array(); > $this->input2 = array_pad($this->input,10,1); > To summarize: <?php class Liste { var $input2; var $input; function Liste() { /* or, if you're using php5: public function __construct() { */ $this->input = array(1,2,3); $this->input2 = array_pad($this->input,10,1); } }

« previous php.general (#196335) next »