search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

Return Type Declarations of PHP 7

Return Type Declarations of PHP 7

PHP: 7.2

PHP 7.x 開始提供了一些新的功能,Return Type Declarations 就是其中一種。

Return Type Declarations 可以宣告定義函式中回轉的資料型態,讓函式的結構更為嚴謹。

範例

// 在函式後方利用 :  宣告 return type 為 int
function returnInt($num): int
{
    return $num;
}

// 123
echo returnInt(123);

// PHP Fatal error:  Uncaught TypeError: Return value of returnInt() must be of the type integer
echo returnInt('String');
Categories: PHP
Tags: PHP



熱門推薦

本文由 blogjohnsonluorg 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦