Construct function
Sofia419
Messages postés
8
Date d'inscription
Statut
Membre
Dernière intervention
-
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
- Multi-function hdd docking 893u3 driver download ✓ - Forum Disque dur / SSD
- (Function(){css.removeclass(document.body,%20'profile_two_columns'); tab_controller.changepage("photos");})() ✓ - Forum Access
- Call to undefined function mysqli_connect() ✓ - Forum PHP
- Facebook profil sans etre ami ✓ - Forum Facebook
- [VBS] Aide Sub/function - Forum VB / VBA
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 ^_^