2020年11月5日 星期四

PHP5 轉移至 PHP7需注意事項

 1、Too few arguments to function

PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function TABLE::__construct(), 0 passed in /home/www/OM/class/class.table.php on line 

10638 and exactly 1 expected in /home/www/OM/class/class.table.php:14

原因是PHP7比較嚴謹(我猜的),所以即使是空值也要給個null

public function __construct($var_cond) => $var_cond=null

大批修改如下:

vi 

%s/$var_cond)/$var_cond=null)/g


2、mysql_xxx to mysqli_xxx

所有mysql開頭的函式請改為mysqli開頭。但有兩個要特別注意的:

mysqli_query($sql, $conn); => mysqli_query($conn,$sql);

mysql_select_db('OM',$conn); => mysqli_select_db($conn,'OM');

這兩個mysql函式的順序跟mysqli相反,記得要調整。

3、PHP Warning:  preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead 

這個很明顯,改一下就好了。但callback似乎有比較多眉角,如果要做到沒有info或warning的話,要再調整一下。

4、PHP Deprecated:  __autoload() is deprecated, use spl_autoload_register() instead

這個也是改一下就好了

5、ereg及split相關函式

ereg() 可以用 preg_match() 替代

ereg_replace() 可以用 preg_replace() 替代

eregi() 用 preg_match() i 引數替代

eregi_replace() 用 preg_replace() i 引數替代

split() 用 preg_split() 替代

spliti() 用 preg_split() 模式 ‘i’ 替代

split -> explode

split -> 因為語法有用到regular expression要改用preg_split

6、iconv()要用mb_convert_encoding取代

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

Replace

public function TSStatus($host, $queryPort)

with

public function __construct($host, $queryPort)

剩下的是環境問題:

1、php-fpm的log在/var/log/php-fpm/www-error,第一次用php-fpm的我不曉得。

2、Mariadb (MySQL)的錯誤訊息:Field `s_symptom` doesn‘t have a default value

要修改設定檔:

cd /etc/my.cnf.d

 vi mariadb-server.cnf

[mysqld]

sql_mode=NO_ENGINE_SUBSTITUTION

3、mysqlimport最後要加上--local



沒有留言:

張貼留言