Résolution problème Atom
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* classe
|
||||
*/
|
||||
class foo
|
||||
{
|
||||
/**
|
||||
* attribut
|
||||
*/
|
||||
function do_foo()
|
||||
{
|
||||
echo "Doing foo.";
|
||||
}
|
||||
|
||||
/**
|
||||
* attribut
|
||||
*/
|
||||
function yohan()
|
||||
{
|
||||
echo "Ce mec est trop fort !";
|
||||
}
|
||||
}
|
||||
|
||||
$bar = new foo;
|
||||
$bar->do_foo();
|
||||
$bar->yohan();
|
||||
|
||||
# classe
|
||||
class Voiture
|
||||
{
|
||||
/**
|
||||
* Déclaration des attributs
|
||||
*/
|
||||
# attributs
|
||||
private $niveau_carburant;
|
||||
private $nombre_portes;
|
||||
private $nombre_roues;
|
||||
|
||||
/**
|
||||
* Cette méthode un peu spéciale est le constructeur, elle est exécutée lorsque vous "créez" votre objet. Elle doit initialiser les attributs de la classe.
|
||||
*/
|
||||
# méthode constructeur
|
||||
public function __construct()
|
||||
{
|
||||
$this->niveau_carburant = 50;
|
||||
$this-> = 3;
|
||||
$this->nombre_roues = 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Première méthode accessible par tous et modifiant le niveau de carburant
|
||||
*/
|
||||
# méthode
|
||||
public function modifier_carburant(int $niveau)
|
||||
{
|
||||
$this->niveau_carburant = $niveau;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seconde méthode accessible à tous et modifiant le nombre de portes
|
||||
*/
|
||||
# méthode
|
||||
public function modifier_nb_portes(int $nb_portes)
|
||||
{
|
||||
$this->nombre_portes = $nb_portes;
|
||||
}
|
||||
}
|
||||
|
||||
$voiture = new Voiture;
|
||||
echo "<pre>";
|
||||
var_dump($voiture);
|
||||
echo "</pre>";
|
||||
|
||||
$voiture->modifier_nb_portes(4);
|
||||
|
||||
echo "<pre>";
|
||||
var_dump($voiture);
|
||||
echo "</pre>";
|
||||
|
||||
echo $voiture['nombre_portes'];
|
||||
|
||||
?>
|
||||
# https://www.vulgarisation-informatique.com/php-poo.php
|
||||
Reference in New Issue
Block a user