17. Ma siccome i tempi cambiano….
(Come, per esempio, usare sempre
Comic Sans per slides)
18. Hello PHP 7
● La performance è migliorata: PHP 7 è fino a due volte più veloce di PHP 5.6
● Supporto per 64-bit
● Molti fatal errors sono ora degli Exceptions
● SAPI ed estensioni vecchi e non supportati sono stati rimossi
● L'operatore null coalescing (??)
● L'operatore del "combined comparison" (detto anche "spaceship operator" (<=>)
● Le dichiarazioni dei Return Type
● Le dichiarazioni degli Scalar Type
● Classi anonimi
20. I seguenti tipi da usare per i parametri possono ora essere forzati:
● string (string)
● integer (int)
● floating-point number (float) nota bene: non numero con la virgola galleggiante
● boolean (bool)
Scalar types
21. ...aumentano i altri tipi che sono stati introdotti in PHP 5:
● class names
● interfaces
● array
● callable
Scalar types (cont.d)
23. <?php
declare(strict_types=1);
// ^^^^^^^^^^^^^^ modalità strict
function sumOfInts(int ...$ints)
{
return array_sum($ints);
}
var_dump(sumOfInts(2, '3', 4.1));
risultato: PHP Fatal error: Uncaught TypeError: Argument 2 passed to
sumOfInts() must be of the type integer, string given, called in...
Scalar types: esempio "strict"
24. <?php
// modalità Coercitivo
function sumOfInts(int ...$ints) : int
{
return array_sum($ints);
}
var_dump(sumOfInts(2, '3', 4.1));
//risultato: int(9)
Scalar return types: esempio coercitivo
25. <?php
declare(strict_types=1);
// ^^^^^^^^^^^^^^ modalità strict
function sumOfInts(int ...$ints) : int
{
return array_sum($ints);
}
var_dump(sumOfInts(2, 3, 4)); // int, int, int
//risultato: int(9)
Scalar return types: esempio "strict"
26. <?php
declare(strict_types=1);
// ^^^^^^^^^^^^^^ modalità strict
function sumOfInts(int ...$ints) : string
{
return array_sum($ints);
}
var_dump(sumOfInts(2, 3, 4)); // int, int, int
risultato: PHP Fatal error: Uncaught TypeError: Return value of sumOfInts() must
be of the type string, integer returned
Scalar return types: esempio "strict"