Posted by Mateusz Markowski on 10/06/06 12:04
Adam napisal(a):
> class matrix {
> public $row1 = &new row();
> public $row2 = &new row();
> public $row3 = &new row();
> public $row4 = &new row();
> public $row5 = &new row();
> public $row6 = &new row();
> public $row7 = &new row();
> public $row8 = &new row();
> public $row9 = &new row();
> }
>
> The problem is is that I guess I cannot use objects within another
> class since this code errors. (Parse error: syntax error, unexpected
> T_NEW in yadda/yadda/yadda.php). Could someone take a second to set me
> right and kindly point me in the right direction? I have a feeling I
> am just not looking at this problem correctly.
A default class property must be string, number or array. "new"
operator is not allowed.
Why are creating so many properties instead an array of them? Try:
class Matrix {
private $rows = array();
public function __construct($howmany)
{
for ($i=0;$i<$howmany;$i++) {
$this->rows[$i] =new Row();
}
}
}
Navigation:
[Reply to this message]
|