php5 升级 php7 版本遇到的问题处理方法总结

为了能够更好的提升系统的安全性,把原来的进销存系统源码升级,遇到了一些问题在这儿总结一下:

1.mysql引擎在php7中不在支持会导致以下错误

Uncaught Error: Call to a member function init() on null 。

其实在init()函数中,有extension_loaded("mysql"),即加载mysql扩展导致的,需要改为mysqli,不过后面的mysql操作函数都需要改成mysqli的对应类型

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

Smarty has a deprecated constructor in /www/platform/library/Platform/View/Smarty/Smarty.class.php
[引自原文]:https://blog.csdn.net/sanbingyutuoniao123/article/details/78614077

原来是smarty模板类还是使用了php4的构造函数的写法,所以找到smarty类后,找到与类同名的函数,将函数名改

为__construct即可。

PHP OOP使用和类名相同的方法名作为构造方法,是 PHP4 的写法,PHP 5中同时支持__construct和类同名方法,但__construct方法具有优先性。

PHP 7开始使用和类名相同的方法名作为构造方法会报E_DEPRECATED级别的错误,提示在未来版本中会彻底抛弃类同名方法作为

构造函数。但程序仍然会正常执行。

<?php
        class a{
                function a(){ // 此处改为 function __construct()
                        
                }
        }
?>

 3.Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP)

在php7中,MYSQL_ASSOC不再是一个常量,将 MYSQL_ASSOC改为MYSQLI_ASSOC,意思是mysqli的方式提取数组,而不再是mysql 。(原因:mysql_fetch_arrayhan函数转为mysqli_fetch_array,参数没有修改

4.汉字显示为???(问号) 的解决办法

mysqli_query($conn,'set names utf8');在使用mysqli_query()查询数据的时候,最好指定字符的编码

原文地址:https://www.cnblogs.com/imustun/p/9828591.html