class Browser
{
// Always declare whether a variable is public or private
private $type = null;
// A constructor - gets excecuted every time you create a class
public function __construct($type)
{
// Note that $type here is not the same as $type above
// The $type above is now $this->type
$this->type = $type; // Store the type variable
}
// Your function e()
public function e()
{
return $this->type;
}
// __toString() method. (May also be useful)
// it gets excecuted every time you echo the class, see below.
public function __toString()
{
return $this->e(); // I chose to return function e() output here
}
}
Exemples d'utilisation:
$b = new Browser('Human'); // Note, that this executes __construct('Human');
echo $b->e(); // Echos 'Human'
$b = new Browser('Lolcat'); // Excecutes __construct('Lolcat');
echo $b->__toString(); // Echos 'Lolcat'
echo $b; // Echos 'Lolcat', equivalent to statement above
//Also:
$c = (string) $b;
echo $c; // Echos 'Lolcat'
vraiment merci son travaillé –
Impossible d'obtenir la mise en forme de travailler. Quelqu'un peut m'aider s'il vous plaît? – markmywords
ce n'est pas important ses travaux grâce –