Fatal error

Bonjour,

j'ai mis ce code

$img = ''. GetAvatarById($v['membreId'],"avatar_organisateur avatar_membre") . '';


il me dit

Fatal error: Cannot use object of type stdClass as array in /var/www/legtux.org/users/site/modules/activites/function.inc.php on line 381

3 réponses

  1. Bonjour

    D'après ton message, il semblerait que $v contienne un objet et non pas un tableau.
    Ajoute un print_r($v); juste avant cette ligne pour voir ce qu'il y a réellement.
    1. Merci il me dit avc print

      Notice: Undefined variable: endScript in /var/www/legtux.org/users/monsite/modules/activites/function.inc.php on line 467
      stdClass Object ( [membre_id] => 91 ) 
      Fatal error: Cannot use object of type stdClass as array in /var/www/legtux.org/users/monsite/modules/activites/function.inc.php on line 381


      ligne 467 et 381

              function GetInscritsAttente($activiteId)
              {
                  global $pdo;
                  $membreIds = $pdo->prepare('SELECT membre_id FROM activite_attente WHERE activite_id='.$activiteId);$membreIds->execute();
                  $str = null;
                  $i = 0;
      
                  while($v = $membreIds->fetch(PDO::FETCH_OBJ))
                  {
                      $i++;
                      if($v!=''){
                      	$sql = 'SELECT membre_id,membre_prenom,membre_localisation FROM forum_membres WHERE membre_id='.$v->membre_id;
      	                $membreInfo = $pdo->query($sql);
      					$minfo = $membreInfo->fetch(PDO::FETCH_OBJ);
      	
      // données additionnelles
       print_r($v);
        	                    $img = ''. GetAvatarById($v['membre_id'],"avatar_tuto_cours_sondage avatar_membre"). '';
      
      						$add='Prénom : ' . $minfo->membre_prenom .'
      						Âge :  ' . GetAgeById($v->membre_id). '
      						Ville :  '.($ville = GetVilleById(GetValueFromQuery('SELECT membre_departement AS value FROM forum_membres WHERE membre_id='.$v->membre_id))).'
      						Je suis : handicape
      						';					
      	                    							
      					$add = $add.$endScript;
      
       	                $str .= "<div class"liste_inscrite_attente">
      					         " . sex2color(id2pseudo($v->membre_id), $v->membre_id) . " (2)
      							 " . $img . "
      							 
      							 " . $add . "</div>";
      
       
       
       
                     }
      							
                }
      
                  return ($str?$str:'Il n\'y a personnes dans la liste.');
      
              }
      
      	
      
              function GetTableauAttente($activiteId)
      
              {
      
                  global $pdo;
      
                  $sql = 'SELECT * FROM activite_attente WHERE activite_id='.$activiteId;
      
                  $membreIds = $pdo->query($sql);
      
                  $tab = array();
      
                  foreach($membreIds as $v)
      
                  {
      
                      array_push($tab,$v['membre_id']);
      
                  }
      
                  
      
                  return $tab;
      
              }
      
              
      	
      	function GetInscrits($activiteId)
      
      	{
      		global $pdo;
      		$membreIds = GetValueFromQuery('SELECT membreInscrit as value FROM activite_sortie WHERE sortie_activite_id='.$activiteId);
      
      		
      
                      $searchTab = array();
      
      		$tab = explode(";",$membreIds);
      		$i=0;
      		foreach($tab as $v)
      
      		{
      			if($v!=''){
      		$membreInfo = $pdo->prepare('SELECT membre_id,membre_prenom,membre_localisation FROM forum_membres WHERE membre_id=?');
      		$membreInfo->execute(array($v));
      		$minfo = $membreInfo->fetch(PDO::FETCH_OBJ);
      
                          // données additionnelles
                          $img = ''. GetAvatarById($v['membreId'],"avatar_commentaire avatar_membre") . '';
      					$add = '' . $img . '
      					Prénom : ' . $minfo->membre_prenom . '
      					Acirc;ge : ' . GetAgeById($v). '
      					Ville : '.($ville = GetVilleById(GetValueFromQuery('SELECT membre_departement AS value FROM forum_membres WHERE membre_id='.$v))).'
      					Je suis : valide
      									';					
      							
      					$add = $add.$endScript;
                         //
      					
      					//if($i>0&&$i%5==0)
      						//$str .= '';
      		    if(is_numeric($v) && (!is_numeric(array_search($v,$searchTab))))
      			
      			        $str .= "" . sex2color(id2pseudo($v),$v) . " (4)
      							 
      							 " . $img . "
      							 
      							 
      							 " . $add . "";
      
                              array_push($searchTab,$v);
      						$i++;
      			}
      		}
      		return $str ;
      	}
      
      
      


      ligne 467 : $add = $add.$endScript;

      ligne 381 : $img = ''. GetAvatarById($v['membre_id'],"avatar_tuto_cours_sondage avatar_membre"). '';

      merci
      1. Notice: Undefined variable: endScript in /var/www/legtux.org/users/monsite/modules/activites/function.inc.php on line 467
        Cette nouvelle erreur n'a aucun rapport avec le print_r, ni a priori avec l'autre erreur. On verra plus tard.
        En ce qui concerne ton "Cannot use object of type stdClass as array", il s'explique très bien : tu précises PDO::FETCH_OBJ dans ton fetch, tu récupères donc un objet.
        Mais ensuite dans $v['membre_id'], tu t'en sers comme d'un tableau, alors qu'un peu plus loin dans $v->membre_id, tu t'en sers bien comme d'un objet.
        Fais ton choix : objet ou tableau, mais ne mélange pas les deux.
        1. En ce qui concerne $endScript, si elle est définie ailleurs, il faut la déclarer en global (comme $pdo) au début de la fonction.