Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/11/2008, 08:53
Casuis
 
Fecha de Ingreso: septiembre-2005
Mensajes: 142
Antigüedad: 18 años, 8 meses
Puntos: 3
Respuesta: Problemita con array de objetos

Prueba a cambiar la clase Service

Código PHP:
class Service{

    private 
$_id;
    private 
$_userComments = array();

    public function  
__toString() 
    {
        
$s .= $this->getId();
        
$s .= ' | ';
        
        foreach (
$this->_userComments as $num => $c) {
            
$s .= $num '. ' $c->getComment() . '<br/>';
        }
        return 
$s;
    }

    public function 
addComment(UserComment $comment){
        
$this->_userComments[] = $comment;
    } 
A ver que tal te va ahora esto de $this->_userComments[] es lo mismo que tu array_push solo que a mi forma de ver más limpio y rapido trabajamos con la variable interna y ahorramos llamadas. Ya me diras.

por cierto, el método getUserComments() no lo has puesto en el código y donde en teoria, tienes el problema.