Detailed explanation of errors about PHP version number

零下一度
Release: 2023-03-13 08:54:01
Original
1558 people have browsed it
<?php
class Car
{
    var $color = "add";
    function Car($color="green") {
        $this->color = $color;
    }
    function what_color() {
        return $this->color;
    }
}

$car = new Car;
echo $car->what_color(),"<br>over";
?>
Copy after login

PHP version number

php 7.0.10

Reported Error

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Car has a deprecated constructor in E:\phpStorm\firstPhp\test.php on line 8

Solution

#Check the information and find## After #php7.0, the constructor with the same name as the class will no longer be supported, and the constructor method will uniformly use __construct().

##Corrected code##

<?php
class Car
{
    public $color = "add";
    function __construct($color="green") {   //注意是双下划线$this->color = $color;
    }
    public function what_color() {
        return $this->color;
    }
}

$car = new Car("red");
echo $car->what_color(),"<br>over";
?>
Copy after login

The above is the detailed content of Detailed explanation of errors about PHP version number. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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 admin@php.cn
Popular Recommendations
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!