PHP5.3/PHP5.4和PHP5.2的一些差别和注意事项

php5.3和之前的版本函数差异

1:Function ereg() is deprecated Error 错误对策



Deprecated: Function ereg() is deprecated in ……



解决方法一: 退回去用php5.2。



解决方法二:继续用php5.3,但是修改devel/devel.modul的460行: if ($errno & (E_ALL ^ E_NOTICE)) { 改为 if ($errno & (E_ALL & ~E_NOTICE & ~E_DEPRECATED)) { 把deprecated错误给忽略掉)



解决方法三:把ereg换成preg_match,ereg_replace也需得换成preg_replace。



只得注意的是 ereg(’^[0-9]‘ 需修改成 preg_match(’/^[0-9]/‘



2: PHP5.3后(set_magic_quotes_runtime(),ereg() )已经关闭



运行php程序出现以下错误

Deprecated: Function set_magic_quotes_runtime() is deprecated





导致这个提示的原因是在PHP5.3后此特性(set_magic_quotes_runtime())已经关闭。

而且在PHP6中已经完全移除此特性。

你可以注释或者删除掉出错的行,或者是在set_magic_quotes_runtime()前面加@符号。





PHP 5.3 ereg() 无法正常使用,提示“Function ereg() is deprecated Error”。问题根源是php中有两种正则表示方法,一个是posix,一个是perl,php6打算废除posix的正则表示方法所以后来就加了个 preg_match。此问题解决办法很简单,在ereg前加个过滤提示信息符号即可:把ereg()变成@ereg()。这样屏蔽了提示信息,但根本问 题还是没有解决,php在5.2版本以前ereg都使用正常,在5.3以后,就要用preg_match来代替ereg。所以就需要变成这样,原来:



ereg("^[0-9]$",$page)



变成:



preg_match("/^[0-9]
$/",$page)



特别提醒:posix与perl的很明显的表达区别就是是否加斜杠,所以与ereg相比,后者在正则的前后分别增加了两个”/”符号,不能缺少。

Tips:此问题在php5.2之前版本不会出现。



Function ereg() is deprecated in drupal-6.15\includes\file.inc on line 904

open the file.inc in a good text editor other than notepad, go to the line number 904 to see the following line. Then comment the line and in the next line type the replaced code. this will solve the instalation issues and also most of other issues related to the same issue.



Change



elseif ($depth >= $min_depth && ereg($mask, $file)) {



to

elseif ($depth >= $min_depth && mb_ereg($mask, $file)) {



mb_ereg fortunatly is not deprecate



升级PHP5.4版本的一些错误

========================================================

“Call-time pass-by-reference has been removed ”

调用时引用传递已被废弃。

当我们这样使用函数(或者类)的话,会产生一个error:

foo(& $var);

实际上,这样用本来就是错的,只是之前的错误级别仅仅是Deprecated而已。

而正确的使用方法应该是在函数定义时:

function foo(& $var) {

}

而在调用时直接传参就行了: foo($var);



========================================================

时区(timezone)必须设置

如果没有通过在配置文件中配置date.timezone 或者代码中通过 date_default_timezone_set()的方式来设定时区的话,以前会进行一些推算,而5.4以后则会删除这个特性。取而代之的是使用“UTC”时间。(点击查看什么是“UTF时间”)



========================================================

E_ALL现在包含E_STRICT

众所周知E_STRICT是不包含在E_ALL里面的,所以我们才会有E_ALL & E_STRICT这种写法。

而到了PHP 5.4中,E_ALL将包括E_STRICT。



========================================================

register_globals被移除

相信很多的PHP都对register_globals深恶痛绝,而register_globals也被认为是万恶之首,早在4.2的时候,register_globals就默认关闭了,而到了5.4就把register_long_arrays和register_globals移除了。One Less Thing to Worry About。



========================================================

默认字符集变成UTF-8

配置文件中的default_charset由原来的ISO-8859-1变成UTF-8。



========================================================

session_is_registered(), session_register() 和 session_unregister() 函数被移除.

这些函数在PHP 5.3中已经被废弃,如果要使用,可以直接对$_SESSION变量用isset(),unset()这样的方式。这些方法被移除后,如果使用会导致error。



========================================================

magic_quotes_gpc和相关的所有函数、ini中的设置

被移除的有配置中的magic_quotes_gpc, magic_quotes_runtime 和 magic_quotes_sybase。而get_magic_quotes_gpc, get_magic_quotes_runtime 虽然被保留了,但是始终会返回 false, set_magic_quotes_runtime 会产生E_CORE_ERROR错误。



========================================================

EXT/SQLITE扩展被移除

别太惊讶了,这次被移除的扩展仅仅是ext/sqlite, 而ext/sqlite3以及 ext/pdo_sqlite并没有被移除。

| 0个评论