php引擎能否向下兼容,PHP 未向下兼容的改变

用户评论:

michael dot darmousseh at gmail dot com (2010-02-03 17:53:00)

Hack way to fix the array_merge problem so that it works with your existing php4 code

{$args=func_get_args();

foreach($argsas$key=>$arg)$args[$key] = (array)$arg;

returncall_user_func_array("array_merge",$args);

}?>

just put it somewhere completely accessible to your codebase and change all of your calls to array_merge to array_merge5.

paul at oconnor-web dot net (2008-04-10 04:17:47)

The __call function will also lowercase the method arguement:

if ($method=='Foo') {

returntrue;

} else {

returnfalse}

}?>

(= false)

Steven (2008-03-19 16:07:29)

Three more that we discovered:

== 1. No longer can re-assign $this ==

The follwoing example works under PHP4 (it outputs "OK"), but produces a fatal error under PHP5:

var$text;

functiona() {$this->text='OK'; }

}

classb{

var$text='NOT OK';

functionb() {$this= newa(); }

}$myClass= newb();

echo$myClass->text;?>

== 2. No comments allowed after shorthand echo block ==

The follwoing example works under PHP4, but produces a sytax error under PHP5.

=//comment?>

== 3. Constructors return a reference as default ==

The follwoing example works under PHP4, but produces an E_NOTICE notice under PHP5.

Removing the ampersand solves the problem

Aggelos Orfanakos (2007-11-08 05:10:02)

As with array_merge(), array_merge_recursive() returns NULL in PHP 5 if a non-array parameter is passed to it.

Sinured (2007-08-10 04:43:00)

Not mentioned above: The PHP/FI 2 function style (old_function aka cfunction) is no longer supported as of PHP 5.

nami (2007-07-26 07:22:44)

addition of the note on 07-Sep-2004 06:40

if you write down your code like this PHP5 will just work fine:

$array_1= array('key1'=>'oranges','key2'=>'apples');$array_2= array('key3'=>'pears','key4'=>'tomatoes');$array_3= array();$arr_gemerged=array_merge($array_1,$array_2,$array_3);

echo"result:
";print_r($arr_gemerged);

echo"
";?>

---

so you have to declare array_3 as array() instead of NULL

kemal djakman (2007-06-22 06:11:15)

The handling of accessing empty property of a class error has also changed:

var$Bar='xxx';

functionF() {

echo$this->$Bar;

}

}$Obj= newFoo();$Obj->F();?>

Notice the $ sign after object dereference opr?  $Bar is empty inside method F.   PHP4 would only generate a warning, PHP5 throws a fatal error

Amir Laher (2007-04-29 14:34:36)

Some other things to be aware of:

some extra strictness:

* object members can no longer be accessed using array-member syntax

* function-calls with too many arguments will now cause errors.

Also, from PHP5.2, custom session handlers are affected:

* Best not to use global objects in custom session-handling functions. These would get destructed *before* the session is written (unless session_write_close() is called explicitly).

(2006-02-28 14:03:24)

is_a have been deprecated. You can simply replace all occurences with the new instanceOf operator, although this will break backwards-compatibility with php4.

dward . maidencreek.com (2004-11-02 00:54:04)

Another change that we've had problems with while trying to use PHP4 code in PHP5 is how $this is carried across static method calls if they are not declared static in PHP5. The main issue was that debug_backtrace() now shows the first class with -> instead of the second with :: in the backtrace element when the method in the second class was called statically (using ::) from a method in the first class.

(2004-09-07 09:40:37)

Be careful with array_merge in PHP5.1 not only a E_WARNING is thrown, but also the result is an empty array. So if you merge two select queries and the last one is empty you will end up with no array at all.

$array_1= array('key1'=>'oranges','key2'=>'apples');$array_2= array('key3'=>'pears','key4'=>'tomatoes');$array_3=null;$arr_gemerged=array_merge($array_1,$array_2,$array_3);print_r($arr_gemerged);

echo"
";?>

Result on php4:

Array ( [key1] => oranges [key2] => apples [key3] => pears [key4] => tomatoes )

Result on php5:

Warning: array_merge() [function.array-merge]: Argument #3 is not an array in /removed/by/danbrown/for/manual.php on line 7

john.g (2004-08-26 10:45:41)

PATH_TRANSLATED is handy when using Apache's ModRewrite engine, as it gives you the name and path of the resulting file rather than the one that was requested by the user. Since PHP 5.0 and Apache 2 no longer support this variable, I created a workaround by adding an environment variable to my ModRewrite command:

Original:

RewriteRule ^/test/(.*)\.php(.*) /test/prefix_$1.php$2

Adjusted:

RewriteRule ^/test/(.*)\.php(.*) /test/prefix_$1.php$2 [E=TARGET:prefix_$1.php]

I could then find out the resulting file name through the super global $_ENV, for instance:

Note: The "REDIRECT_" prefix appears to be allocated automatically by ModRewrite.

cyberhorse (2004-08-05 10:07:39)

clone() is a php function now.

if you create a subclass, it no longer uses samename methods in superclass as a constructor.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值