<?phpclass 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
The reported error
Deprecated: Methods with the same name as their class is not being constructors in a future version of PHP; Car has a deprecated constructor in E:\phpStorm\firstPhp\test.php on line 8
How to Solve
After reviewing the data, it is found that php7.0 will no longer support the same construction method as the class name, and the construction method uses __construct () uniformly.
Post-correction Code
<?phpclass car{public $color = "Add"; function __construct ($color = "green") { //note is double underlined $this->color = $color; } Public Function What_color () { return $this->color; }} $car = new Car ("Red"), Echo $car->what_color (), "<br>over";? >
Deprecated:methods with the same name as their class is not being constructors in a future version of PHP