dongpo4197 2017-04-05 11:35
浏览 47
已采纳

如何在PHP项目中找到所有出现的“call-time pass-by-reference”并删除/修复它们?

Call-time pass-by-reference was deprecated in PHP 5.3.0 (2009) and it was removed as of PHP 5.4.0 (2012). But still I meet this problem on older PHP projects when migrating them to new server. How to find all occurences of "call-time pass-by-reference" in PHP project and remove/repair them?

  • 写回答

1条回答 默认 最新

  • dslfjrmz70457 2017-04-05 11:35
    关注

    There is no automatic way to do this (at least I have not found any). It must be done manually. Call-time pass-by-references can be found in project files quite precisely by following regex (use your IDE to launch regex serach):

    (?<!function)[:> ][a-zA-Z0-9_]+(?<!foreach|array)\s?\([^()]*&\$
    

    Found occurences you must repair one by one manually. You have to:

    • Remove the ampersand sign in function/method calls. E.g. something like $myResult = myFunction(&$myVar) you will rewrite to $myResult = myFunction($myVar).
    • Check if myFunction() is defined with first argument passed by reference like function myFunction(&$myArg1). If not (it means the ampersand is missing in definition) then you must repair it and add the ampersand
    • If the ampersand was missing in the definition of myFunction() then you must check if all calls of myFunction() in project are done with "call-time pass-by-reference". If yes then you are done. If not (it means there are calls of myFunction() without "call-time pass-by-reference") then you must consider if it changes something if you use pass-by-reference and if yes then you should write a pas-by-value of myFunction() and use it for these occurences
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部