-
类静态方法的调用规范化
php5.2
class类中public方法可直接用 类名::方法名() 调用
php5.6 会报错Message: Non-static method unify_model::getMenu() should not be called statically, assuming $this from incompatible context
-
一些函数执行失败
a.json_decode
处理特殊字符失败
5.6后版本的PHP,JSON处理数据时,遇到非UTF-8特殊字符,会直接返回false,之前则是会将特殊字符转化为NULL。这样会导致JSON无法解压/压缩数据成功。b.
mcrypt_encrypt
加密失败
当参数密钥key长度大于8位时,函数返回false,PHP 5.6
版本后,不再接受无效长度的key and iv
参数
如果参数密钥key长度大于8位,mcrypt_decrypt()
函数会产生警告并且返回 false,导致加密失败。c. curl模拟post上传文件不能通过@文件来进行上传了
5.5之前都可以通过@/tmp/test.jpg这样的方式直接上传,5.5之后,CURLOPT_SAFE_UPLOAD
默认为true,不能通过@文件上传了。
解决方案: 将curl句柄CURLOPT_SAFE_UPLOAD
设置为false。$ch = curl_init(); $data = array( ‘i’ => ‘@/Users/zmx/Desktop/demo.jpg’, ‘q’ => 80, ‘t’ => ‘160×160′, ); curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); //here curl_setopt($ch, CURLOPT_URL, $upload_api); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HEADER, 1); $result = curl_exec($ch); curl_close($ch);
或者改用 CURLFile 类 http://php.net/manual/en/class.curlfile.php
工作中
curl POST
上传文件示例:$data = array( //.";type=".$filedata['type'].";filename=".$filedata['name'] // 'filedata' => '@'.realpath($params['data']['tmp_name']) // 5.5之前的写法 'filedata' => new CURLFile( realpath($params['data']['tmp_name']) ) // 5.5之后推荐的写法 ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url); curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $data); curl_setopt( $ch, CURLOPT_HEADER, false); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true); //添加如下head头就可传输大于1024字节请求 curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $ch, CURLOPT_TIMEOUT, 500 ); $result = curl_exec($ch); curl_close($ch);
d. mysql_connect 连接数据库失败
PHP5.5
以后,mysql
扩展已经被移除,现在只能使用mysqli
和pdo
连接mysql
数据库。
解决方案: 将mysql
扩展换为mysqli
或者pdo
以兼容新版PHP。 -
php高版本废弃$HTTP_RAW_POST_DATA
在高版本 php 的发版说明中都有
$HTTP_RAW_POST_DATA
即将(已经)取消,请改用从php://input
中读取 的声明Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set ‘always_populate_raw_post_data’ to ‘-1’ in php.ini and use the php://input stream instead. in Unknown on line 0
解决方案:
修改php.ini中 always_populate_raw_post_data = -1
$HTTP_RAW_POST_DATA
详解见我另外一篇博文: -
loading…