Bonjour,

je débute avec les classes en php et j'ai un petit soucis...

J'ai 2 objets : "Commande" et "Client" et une page test.php

voici le code :

Commande.class.php ([edit])
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
class Commande{	
	var $id=null;
	var $client=null;
 
	function Commande($id)
	{
		require_once("sources/Client.class.php");
		$this->id=$id;				
		$this->client=new Client('1');
	}	
}
?>

Client.class.php ([edit])
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<?php
class Client{	
	var $id=null;
	var $nom=null;
 
	function Client($id)
	{
		$this->id=$id;				
		$this->nom="toto";
	}	
}
?>

test.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
<?php
 
	$id_object=1;
	require_once("sources/Commande.class.php");
	$Commande = new Commande($id_object);
 
	echo "id_commande : $Commande->id<br/>";
 
	echo "nom_client : $Commande->client->nom<br/>";
?>

voilà mon problème est quand je veux afficher le nom du client.

Que dois-je mettre à la place de $Commande->client->nom ???


Merci d'avance

Lipao