PHP7 will be a major version update of the PHP scripting language. It will also bring significant performance improvements and new features, as well as improve some outdated functions. This release will focus on performance enhancements and originate from the phpng branch of the PHP version tree.
In PHP7, a new feature, return type declaration has been introduced. A return type declaration specifies the type of value returned by a function. The following article mainly introduces you to the relevant information of the type declaration of the new features of PHP 7. The introduction in the article is very detailed. Friends in need can refer to it. Let’s take a look together.
Preface
PHP7 makes type declaration possible. The types of formal parameter type declaration supported by PHP 7 are as follows
Integer type
StringType
##Function shape participating return type Declaring the demo is as follows
/** * @author 袁超*/ class Demo{ /** * int $name 则是形参类型声明 * : int 是返回类型声明 */ public function age(int $age) : int { return $age; } }
int $namethat the function is required to receive. The parameters must be of type int. After the parentheses in the parameter list, we follow: int, which declares the return of our function
Data type
$demo = new Demo(); $demo->age(10.23); // 我们传递的是 float 型参数,也能通过检查
floattype parameter, but the code can still run normally
declare(strict_type=1);
Uncaught Type Error
The above is the detailed content of New features in PHP 7: type declarations. For more information, please follow other related articles on the PHP Chinese website!