Usage example of PHP7 anonymous class (code)

不言
Release: 2023-04-05 07:30:01
forward
1593 people have browsed it

The content of this article is about the usage examples (code) of PHP7 anonymous classes. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

num = 1;
    }
    protected function bar(): int {
        return 10;
    }

    public function drive() {
        return new class($this->num) extends An{
            protected $id;

            public function __construct($num) {
                $this->id = $num;
            }
            public function ea() {
                return $this->id + $this->age + $this->bar();
            }
        };
    }
}
echo (new An())->drive()->ea();
Copy after login
rrree

The above is the detailed content of Usage example of PHP7 anonymous class (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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!