Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP

<?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版本号

php 7.0.10

所报错误

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

解决方式

查阅资料,发现php7.0之后将不再支持与类名相同的构造方法,构造方法统一使用 __construct()。

改正后代码

<?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";
?>
时间: 2024-08-07 21:03:50

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP的相关文章

PHP 报错:Deprecated: Methods with the same name as their class will not be constructor...

报着个错的原因是 最近把一个项目从php5.6升级到了php7 报如下错误: Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP;nusoap_xmlschema has a deprecated constructor in 原因是原项目还是采用的php5.6构造函数的写法 一个类下边会跟一个相同名字的方法名. PHP 7开始使用和类名

PHP 5.6 中 Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version

在使用数组转换为XML 时,出现这种错误 Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. 特别是在微信开发的时候,字符串转换成XML时,有可能导致这种问题. 解决方法 找到php.ini  文件, 把always_populate_raw_post_data  修改为-1 就行了. always_populate_raw_post_data=-1

FutureWarning: Passing (type, 1) or &#39;1type&#39; as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / &#39;(1,)type&#39;.

关于报错信息 C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe E:/RBM_tf2.0_CNN/rmb_my/model_use.py C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarn

ESPCMS做的网站,报错Deprecated: mysql_pconnect(): 或 Deprecated: Methods with the same name as their class

PHP 5.5版本报如下错误: PHP 7.0版本,报如下错误: 方法很简单,把PHP版本降到5.3以下就好,5.2测试也可以; 原文地址:https://www.cnblogs.com/ybtxwd/p/9729148.html

关于nodejs DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.

const mongoose = require('mongoose') mongoose.connect("mongodb://localhost:27017/study", {useNewUrlParser:true}, function(err){ if(err){ console.log('Connection Error:' + err) }else{ console.log('Connection success!') } }) 原文地址:https://www.cnblo

ECshop 迁移到 PHP7版本时遇到的兼容性问题,ecshopphp7

ECshop 迁移到 PHP7版本时遇到的兼容性问题,ecshopphp7 在 PHP7 上安装 ECShop V2.7.3时,报错! Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; ECS has a deprecated constructor in /usr/local/nginx/html/ecshop/upload/inc

node----DeprecationWarning: current URL string parser is deprecated和Port 3000 is already in use的问题

首先,安装了express和supervisor: 在package.json中: "scripts": { "start": "supervisor ./bin/www" }, 项目根目录下的命令窗口中运行:npm start 但结果却出现以下情况: DeprecationWarning: current URL string parser is deprecated, and will be removed in a future versi

jquery 编程的最佳实践

Loading jQuery Always try to use a CDN to include jQuery on your page. <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>    <script>window.jQuery || document.wri

iOS 基础类解析 - NSObject

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. NSObject Class Reference Inherits from none (NSObject is a root class) Co