©
이 문서에서는 PHP 중국어 웹사이트 매뉴얼 풀어 주다
尽管大部分现有的 PHP 5 代码不需要任何改变就可以正常运行,但请注意一些不向后兼容的变更:
FALSE
。 调用 set_magic_quotes_runtime() 将产生一个 E_CORE_ERROR
级别的错误。
E_WARNING
错误。
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" 。
NULL
、 FALSE
、或 一个空字符串被添加成一个对象的属性时将发出一条 E_WARNING
级别的错误,而不是 E_STRICT
。
FALSE
。
E_STRICT
错误。
下列关键字现在被 保留 ,且不能用于函数名或类名。
下列函数已从 PHP 中移除:
[#1] karl at kandrsoftware dot com [2015-10-11 22:28:59]
Using the '
<?php' tag to open PHP blocks is no longer allowed.
This worked in PHP 5.3:
<?php
// some code here
?>
But in PHP 5.4 you'll get an 'Unexpected end of file' error ...with the error indicating the last line of the file, which is not very useful in finding this kind of thing.
What you need to do is use '
<?php' to open your PHP blocks, like this:
<?php
// some code here
?>
[#2] contact at nouslisons dot com [2015-03-12 09:38:16]
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');
[#3] ky dot patterson at adlinkr dot com [2014-07-23 19:34:44]
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.
[#4] blagdan at gmail dot com [2014-01-30 14:41:21]
'<?if'... worked in 5.3 as equivalent of '<?php if'... In 5.4 it's converted to '<!--?if'...
[#5] anton at zebooka dot com [2013-09-05 03:18:34]
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
[#6] the dot mail dot bg at gmail dot com [2013-08-22 15:03:23]
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".
[#7] luis at portanel dot com [2013-03-07 17:46:36]
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.
[#8] Chris [2013-01-05 15:00:38]
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' );
}
?>