PHP 7.1.5 Released


尽管大部分现有的 PHP 5 代码不需要任何改变就可以正常运行,但请注意一些不向后兼容的变更:

  • 不再支持 安全模式 。任何依赖安全模式的应用在安全方面都需要进行调整。
  • 移除 魔术引号 。为避免出现安全问题,依赖此特性的应用可能需要升级。 get_magic_quotes_gpc()get_magic_quotes_runtime() 现在总是返回 FALSE 。 调用 set_magic_quotes_runtime() 将产生一个 E_CORE_ERROR 级别的错误。
  • register_globalsregister_long_arrays php.ini 指令被移除。
  • 调用时的引用传递 被移除。
  • breakcontinue 语句不再接受可变参数( 比如: break 1 + foo() * $bar; )。像类似 break 2; 这样的固定参数仍可使用。受此变化影响,不再允许出现 break 0;continue 0;
  • 日期与时间扩展 中,不再支持时区使用 TZ(TimeZone)环境变量设置。必须使用 date.timezone php.ini 配置选项或 date_default_timezone_set() 函数来指定时区。PHP 将不再尝试猜测时区,而是回退到“UTC”并发出一条 E_WARNING 错误。
  • 非数字的字符串偏移量,比如 $a['foo'] 此处 $a 是一个字符串,现在使用 isset() 时返回 false,使用 empty() 时返回 true,并产生一条 E_WARNING 错误。偏移量类型是布尔和 null 则产生一条 E_NOTICE 错误。 数字字符串(比如 $a['2'] )仍像以前一样运行。注意像类似 '12.3''5 foobar' 这样的偏移量将被视为非数字并产生一条 E_WARNING 错误,但因为向后兼容的原因它们会被分别转换成 12 和 5 。 注意:下列代码返回不同的结果。 $str='abc';var_dump(isset($str['x'])); // 在 PHP 5.4 或更新版本返回 false,但在 PHP 5.3 或更低版本返回 true
  • 数组转换成字符串将产生一条 E_NOTICE 级别的错误,但返回的结果仍是字符串 "Array"
  • NULLFALSE 、或 一个空字符串被添加成一个对象的属性时将发出一条 E_WARNING 级别的错误,而不是 E_STRICT
  • 现在参数名使用全局变量将会导致一个致命错误。禁止类似 function foo($_GET, $_POST) {} 这样的代码。
  • Salsa10 和 Salsa20 哈希算法 被移除。
  • 当使用两个空数组作为参数时, array_combine() 现在返回 array() 而不是 FALSE
  • htmlentities() 将像 htmlspecialchars() 一样处理亚洲字符集,这是以前 PHP 版本的处理情况,但现在将会发出一条 E_STRICT 错误。
  • 强烈建议不要再使用 eregi() ,此特性在最新版本中被移除。

下列关键字现在被 保留 ,且不能用于函数名或类名。

下列函数已从 PHP 中移除:

add a note add a note

User Contributed Notes 7 notes

ky dot patterson at adlinkr dot com
2 years ago
If you have content that is not 100% UTF-8 then TAKE NOTE:

Starting in PHP 5.4 htmlspecialchars() and htmlentities() assume charset=UTF-8 by default AND WILL RETURN BLANK IF YOUR INPUT IS NOT VALID UTF-8.

So if you have a lot of function calls that look like this:
echo htmlspecialchars($input);
// or
echo htmlentities($input);
i.e. no charset and no flags -- and $input is ISO-8859 (or anything else apart from 7-bit ASCII or UTF-8) -- then PHP 5.4 and 5.5 will return an empty string, and you will be surprised and probably unhappy.

This is apparently a feature, not a bug.
4 years ago
Missing some chars like german umlauts after use of htmlspecialchars? That's because the third param encoding has changed it's default value in PHP 5.4 from ISO-8859-1 to UTF-8.

Possible solution #1:
Change your code from this ...
<?php htmlspecialchars( 'äöü' ); ?>
... to this:
<?php htmlspecialchars ( 'äöü' , ENT_COMPAT | ENT_HTML401 , 'ISO-8859-1' ); ?>

Possible solution #2:
Create a wrapper function and replace htmlspecialchars( to i.e. isohtmlspecialchars( with your IDE/editor/shell...

Example of a wrapper function:
function isohtmlspecialchars( $str ){
htmlspecialchars ( $str , ENT_COMPAT | ENT_HTML401 , 'ISO-8859-1' );
anton at zebooka dot com
3 years ago
It seems that starting of PHP 5.4 you can not override class method with different signature.

class A
    public function
doSomething($a, $b)

B extends A
    public function

PHP Strict standards:  Declaration of B::doSomething() should be compatible with A::doSomething(B $a) in Command line code on line 1
the dot mail dot bg at gmail dot com
3 years ago
There should be samples given here. There are many ways to do such coversion:

Converting an array to a string will now generate an E_NOTICE level error, but the result of the cast will still be the string "Array".
contact at nouslisons dot com
2 years ago
Be careful, in php 5.4. \e in string mean the escape character !
So you will have error for windows path:
$a = "c:\extend\toto.txt";

AND for date function:
echo date ("\t\h\e dmy");
you will have an escape character in your source instead "e"

The workaround I found is simple quote:
echo date ('\t\h\e dmy');
luis at portanel dot com
4 years ago
It's not a PHP version incompatibility itself, but it's important to know that Microsoft dropped the php_mssql.dll support for the "mssql_" funcitions since this version.

To connect to a MSSQL database since 5.4, one good alternative are the PDO drivers.
blagdan at gmail dot com
3 years ago
'<?if'... worked in 5.3 as equivalent of '<?php if'... In 5.4 it's converted to '<!--?if'...
To Top