Home  >  Article  >  Backend Development  >  About scalar type and return value type declaration in PHP7

About scalar type and return value type declaration in PHP7

藏色散人
藏色散人forward
2020-11-16 13:46:191727browse

A question: Are you writing code using new features?

Strict mode
php declare(strict_types=1);

Settings passed in Parameters, and return values ​​of outgoing parameters<pre class="brush:php;toolbar:false">class Person(){     public function name(string $name):string    {         return &quot;名称:&quot;.$name;     }     public function age(int $age):string    {         return &quot;年龄:&quot;.$age;     }}</pre>

Custom return type
class Address(){
    public function getAddress(int $age):string    {
        return ['street'=>'street1','country'=>'china'];
    }}class Person(){

    public function name(string $name):string    {
        return "名称:".$name;
    }

    public function age(int $age):string    {
        return "年龄:".$age;
    }

    public function age(int $age):Address    {
        return new Address();
    }}

The above is the detailed content of About scalar type and return value type declaration in PHP7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete