Utilisation d’instance comme paramètre

Author:


Download

<?php
    class Employes {
        public $fonction;
        public $nom;
        public $prenom;
        public $montant;

        function __construct( $fonction, $prenom, $mainName, $montant ) {
            $this->fonction     = $fonction;
            $this->nom  = $mainName;
            $this->prenom = $prenom;
            $this->montant     = $montant;
        }

        function getNomComplet()
        {
            return "{$this->nom}" . " {$this->prenom}";
        }
    }

class PrimeEmploye
{
    public function primer( $employe )
    {
        $str  = "{$employe->fonction}: ";
        $str .= $employe->getNomComplet();
        $str .= " ({$employe->montant})";
        print $str;
    }
}
$employe1 = new Employes( "Agent marketing", "Dick", "Aflack", 1520 );
$promo = new PrimeEmploye();
$promo->primer( $employe1 );

?>

Leave a Reply

Your email address will not be published. Required fields are marked *


+ 2 = seven