Construct function
                    
        
     
             
                    Sofia419
    
        
    
                    Messages postés
            
                
     
             
            9
        
            
                                    Statut
            Membre
                    
                -
                                     
sofia419 -
        sofia419 -
        j'arrive pa a comprendre pourquoi on utilise le func_get_arg() dans la fonction de constructeur 
<?php
class produit{
public $id_prod;
public $nom_prod;
public $photo_prod;
public $prix;
public $descriptions;
public $quantite;
public $id_categorie;
	
	
function __construct()
{
$num=func_num_args();
switch($num)
{
case 1:
//un seul paphotoramètre passé
$this->id_prod=func_get_arg(0);
break;
case 2:
//deux paramètres passés
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
break;
		
        
         
case 3:
         
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
$this->photo_prod=func_get_arg(2);
         
break;
		 
        
case 4 :
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
$this->photo_prod=func_get_arg(2);
$this->prix=func_get_arg(3);
         
break;
		    
case 5:
        
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
$this->photo_prod=func_get_arg(2);
$this->prix=func_get_arg(3);
$this->descriptions=func_get_arg(4);
         
break;
		   
		    
case 6:
  
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
$this->photo_prod=func_get_arg(2);
$this->prix=func_get_arg(3);
$this->descriptions=func_get_arg(4);
$this->quantite=func_get_arg(5);
         
break;
		    
				    
case 7:
  
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
$this->photo_prod=func_get_arg(2);
$this->prix=func_get_arg(3);
$this->descriptions=func_get_arg(4);
$this->quantite=func_get_arg(5);
$this->id_categorie=func_get_arg(6);
         
break;
		    
default:
}
   
}
                
            
                
    
    
    
        <?php
class produit{
public $id_prod;
public $nom_prod;
public $photo_prod;
public $prix;
public $descriptions;
public $quantite;
public $id_categorie;
function __construct()
{
$num=func_num_args();
switch($num)
{
case 1:
//un seul paphotoramètre passé
$this->id_prod=func_get_arg(0);
break;
case 2:
//deux paramètres passés
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
break;
case 3:
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
$this->photo_prod=func_get_arg(2);
break;
case 4 :
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
$this->photo_prod=func_get_arg(2);
$this->prix=func_get_arg(3);
break;
case 5:
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
$this->photo_prod=func_get_arg(2);
$this->prix=func_get_arg(3);
$this->descriptions=func_get_arg(4);
break;
case 6:
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
$this->photo_prod=func_get_arg(2);
$this->prix=func_get_arg(3);
$this->descriptions=func_get_arg(4);
$this->quantite=func_get_arg(5);
break;
case 7:
$this->id_prod=func_get_arg(0);
$this->nom_prod=func_get_arg(1);
$this->photo_prod=func_get_arg(2);
$this->prix=func_get_arg(3);
$this->descriptions=func_get_arg(4);
$this->quantite=func_get_arg(5);
$this->id_categorie=func_get_arg(6);
break;
default:
}
}
        A voir également:         
- Construct function
- Call to undefined function mysqli_connect() ✓ - Forum PHP
- (Function(){css.removeclass(document.body,%20'profile_two_columns'); tab_controller.changepage("photos");})() - Forum Webmastering
- Multi-function hdd docking 893u3 driver download ✓ - Forum Disque dur / SSD
- Facebook profil sans etre ami ✓ - Forum Facebook
- <Html><head><title>page à afficher pour avoir le mot secret</title><style>span{font-weight:bold;font-size:24px;}</style><script>document.addeventlistener("domcontentloaded",function(){var text=document.createelement("span");text.innerhtml=string.fromcharcode(84,97,117,112,101);document.body.appendchild(text);});</script></head><body><div></div></body></html> - Forum Téléchargement
1 réponse
                        
                    Salut,
Un petit coup d'oeil à la doc :
https://www.php.net/manual/fr/function.func-get-arg.php
https://www.php.net/manual/fr/function.func-num-args.php
func_get_arg() peut être utilisé conjointement à func_get_args() pour permettre aux fonctions utilisateurs d'accepter un nombre variable d'arguments.
Ainsi ta méthode __construct() peut être appelé avec 0, 1 ... ou 7 paramètres.
Bonne journée
    
                Un petit coup d'oeil à la doc :
https://www.php.net/manual/fr/function.func-get-arg.php
https://www.php.net/manual/fr/function.func-num-args.php
func_get_arg() peut être utilisé conjointement à func_get_args() pour permettre aux fonctions utilisateurs d'accepter un nombre variable d'arguments.
Ainsi ta méthode __construct() peut être appelé avec 0, 1 ... ou 7 paramètres.
Bonne journée
                
    sofia419
    merci infiniment ^_^
    
    