Php en ligne de commande

$identifiant = $_GET['utilisateur'] ?? 'aucun';

$identifiant = $_GET['utilisateur'] ?? $_POST['utilisateur'] ?? 'aucun';

Syntaxe heredoc

echo <<<EOT
<strong>Mon nom est "$name". J'affiche quelques $foo->foo.</strong>
Maintenant, j'affiche quelques {$foo->bar[1]}.
Et ceci devrait afficher un 'A' majuscule : \x41
EOT;

opérateur Spaceship

<?php
// Entiers
echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1

// Nombres à virgule flottante
echo 1.5 <=> 1.5; // 0
echo 1.5 <=> 2.5; // -1
echo 2.5 <=> 1.5; // 1
 
// Chaînes de caractères
echo "a" <=> "a"; // 0
echo "a" <=> "b"; // -1
echo "b" <=> "a"; // 1

Classes anonymes

<?php
interface Logger {
    public function log(string $msg);
}

class Application {
    private $logger;

    public function getLogger(): Logger {
         return $this->logger;
    }

    public function setLogger(Logger $logger) {
         $this->logger = $logger;
    }
}

$app = new Application;
$app->setLogger(new class implements Logger {
    public function log(string $msg) {
        echo $msg;
    }
});

var_dump($app->getLogger());

Fonction sscanf

https://www.php.net/manual/fr/function.sscanf.php

fonction pour “éclater” une chaîne
<?php
// Lecture d'un numéro de série
list($serial) = sscanf("SN/2350001", "SN/%d");
// et la date de fabrication
$mandate = "January 01 2000";
list($month, $day, $year) = sscanf($mandate, "%s %d %d");
echo "Le produit $serial a été fabriqué le : $year-" . substr($month, 0, 3) . "-$day\n";


// this function is a great way to get integer rgb values from the html equivalent hex.
list($r, $g, $b) = sscanf('00ccff', '%2x%2x%2x');