how to correctly create an array of the same type objects ?
First I thought I should declare every element of an array as my object
and it works (I'll skip class definition, it is irrelevant):
$arr=array();
for($x=0;$x<=16;$x++)
{
$arr[$x]= new clsLink();
}
$arr[0]->url='http://yahoo.com';
$arr[0]->desc='yahoo directory';
$arr[1]->url='http://google.com';
$arr[1]->desc='google se';
and so on ... total 16 objcets/elements in $arr
then I set only first element as my object and php
did not complain when I used second element as my object
$arr=array();
$arr[0]= new clsLink();
$arr[0]->url='http://yahoo.com';
$arr[0]->desc='yahoo directory';
$arr[1]->url='http://google.com';
$arr[1]->desc='google se';
and so on ... total 16 objcets/elements in $arr
then I totaly removed any declarations
and just started using arr as if every element was my
object and now I am honestly lost which way is correct to
create an array of the same type of objects ?
$arr=array();
$arr[0]->url='http://yahoo.com';
$arr[0]->desc='yahoo directory';
$arr[1]->url='http://google.com';
$arr[1]->desc='google se';
and so on ... total 16 objcets/elements in $arr