Deprecated:methods with the same name as their class is not being constructors in a future version of PHP

Source: Internet
Author: User
Tags deprecated

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.