Recentemente stavo verificando su PHP 7, nello specifico return type declaration e type hinting. Ho compilato PHP 7 dal sorgente (ramo principale da Github) ed eseguendolo nella casella virtuale Ubuntu 14.04. Ho provato a eseguire il codice seguente per ottenere un test del nuovo Exceptions. Ma ha dato una pagina vuota.Pagina vuota se dichiaro (strict_types = 1); in PHP 7 all'inizio del file
Quindi mi rendo conto che devo impostare l'errore per essere visualizzato sullo schermo. Così ho aggiunto vecchio stile ini_set('display_errors', 1);
come qui di seguito,
<?php
ini_set('display_errors', 1);
function test(): string {
return [];
}
echo test();
che mi ha dato seguito TypeError
come previsto in base a questo Throwable interface RFC
Fatal error: Uncaught TypeError: Return value of test() must be of the type string, array returned in /usr/share/nginx/html/test.php on line 7 in /usr/share/nginx/html/test.php:7 Stack trace: #0 /usr/share/nginx/html/test.php(10): test() #1 {main} thrown in /usr/share/nginx/html/test.php on line 7
Scavando ulteriormente ho aggiunto declare(strict_types=1);
in alto come in basso,
<?php declare(strict_types=1);
ini_set('display_errors', 1);
function test(): string {
return [];
}
echo test();
e bang, l'errore è appena scomparso lasciandomi con una pagina bianca. Non riesco a capire perché mi sta dando una pagina vuota?
Grazie per essere tornato per rispondere, probabilmente avrei incontrato la stessa cosa quando finalmente ho iniziato a giocare con 7 – dops