<?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!