The output of an array of objects
Posted: Thu Feb 07, 2008 10:14 am
Hi to all!
As you can view in the code, $_moduli is an array of objects... How i can access to this data? Foreach doesn't work...
i did:
and now? thank you!
Code: Select all
class Corso {
protected $_nome;
protected $_tipologia;
protected $_moduli = array();
public function __construct($nome, $tipologia) {
$this->_nome = $nome;
$this->_tipologia = $tipologia;
}
public function setModuli(array $moduli) {
foreach($moduli as $ii => $moduli) {
if (!($moduli instanceof Modulo)) {
throw new Exception("Elemento in indice $ii non è una valida istanza della classe modulo");
}
else{
$this->_moduli[] = $moduli;
}
}
}
public function getModuli() {
return $this->_moduli;
}
}
i did:
Code: Select all
$moduli = array(
new Modulo('cip'),
new Modulo('ciop'),
);
$corso = new Corso('nome', 'tipologia');
$corso->setModuli($moduli);
$corso->getModuli();
and now? thank you!