Home > Backend Development > PHP7 > body text

About scalar type and return value type declaration in PHP7

藏色散人
Release: 2023-02-17 18:02:01
forward
1605 people have browsed it

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

class Person(){

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

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

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();
    }}
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!