color = $color; } function what_color() { return $this->color; }}$car = new"/> color = $color; } function what_color() { return $this->color; }}$car = new">

Home >Backend Development >PHP Tutorial >Detailed explanation of errors about PHP version number

Detailed explanation of errors about PHP version number

零下一度
零下一度Original
2017-07-21 13:21:231598browse
<?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";
?>

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";
?>

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!

Statement:
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