略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 不向后兼容的变更

2024-03-27

不向后兼容的变更

尽管大部分现有的 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 3 notes

up
40
ky dot patterson at adlinkr dot com
4 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:
<?php
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.
up
30
Chris
6 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:
<?php
function isohtmlspecialchars( $str ){
   return
htmlspecialchars ( $str , ENT_COMPAT | ENT_HTML401 , 'ISO-8859-1' );
}
?>
up
20
anton at zebooka dot com
5 years ago
It seems that starting of PHP 5.4 you can not override class method with different signature.

Example:
<?php
class A
{
    public function
doSomething($a, $b)
    {
    }
}

class
B extends A
{
    public function
doSomething($c)
    {
    }
}
?>

PHP Strict standards:  Declaration of B::doSomething() should be compatible with A::doSomething(B $a) in Command line code on line 1

官方地址:https://www.php.net/manual/en/migration54.incompatible.php

冷却塔厂家 广告
-- 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3