Recently I was checking out on PHP 7, specifically return type declaration and type hinting. I have compiled PHP 7 from source(master branch from Github) and running it in Ubuntu 14.04 virtual box. I tried to run following code to get a test of new Exceptions. But it Gave a blank page.
<?php
function test(): string {
return [];
}
echo test();
Then I realize I have to set error to be displayed on screen. So I added old fashioned ini_set('display_errors', 1);
like below,
<?php
ini_set('display_errors', 1);
function test(): string {
return [];
}
echo test();
that gave me following TypeError
as expected according to this 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
Digging further I added declare(strict_types=1);
at the top as below,
<?php declare(strict_types=1);
ini_set('display_errors', 1);
function test(): string {
return [];
}
echo test();
and bang, error just got disappeared leaving me with blank page. I cant figure out why it is giving me a blank page?