doucai4274 2015-11-04 21:34
浏览 47
已采纳

PHP与&和Joomla严重错误

I'm helping a client troubleshoot some issues that have, so far as I can tell, arisen after their update to PHP 5.5 (Joomla is currently 2.5.20). The errors are getting thrown from some lines that are attributed to the Joomla CMS (though I don't think that's the reason). Either way, here are few code snippets and their respective errors that I need help with:

$app =& JFactory::getApplication();

PHP Strict Standards: Only variables should be assigned by reference...


public function getModel($name = 'Submission', $prefix = 'AwardAdminModel') 
        {
            $model = parent::getModel($name, $prefix, array('ignore_request' => true));
            return $model;
        }

getModel() should be compatible with JController::getModel($name = '', $prefix = '', $config = Array)


function display($cachable = false) 
    {
        JRequest::setVar('view', JRequest::getCmd('view', 'Submissions'));
        parent::display($cachable);
    }

display() should be compatible with JController::display($cachable = false, $urlparams = false)


Now I've never used ampersand with my PHP before but courtesy of the PHP manual I have some inclination as to what it does but I'm not sure why it's throwing a fit - I'm sure I could just remove it and be safe.

The getModel method is labeled as a proxy in the signature and sure enough, it calls it proper with 3 arguments within itself so I'm not sure why that's a problem.

Any helpful tips or solutions would be much appreciated.

Thanks.

  • 写回答

1条回答 默认 最新

  • dongpangzan6425 2015-11-04 22:43
    关注

    As a general rule, I would always advise against changing vendor code. It can create complications in future with vendor updates. Consider whether a lower version of PHP matching the vendor expectations may be suitable or investigate forking the vendors source repository so that future vendor updates can be merged it.

    To answer your question: The first error:

    PHP Strict Standards: Only variables should be assigned by reference...

    In PHP & is often used to assign aliases on items. This enables an item that may change to be known by more than one name and can sometimes be useful. It also used to be used in PHP to make it more efficient when using different names for the same item because PHP used to make copies every time something was assigned a new name.

    The efficiency of PHP in this latter scenario has been significantly improved since v5 and PHP are strongly encouraging the use of & for aliasing only variables and only when it makes sense logically for the purpose of the code The return value of a function cannot be aliased because logically it was inside the local scope of a function which no longer exists.

    So yes it is very likely safe to replace =& with = on function calls.

    Second error:

    getModel() should be compatible with JController::getModel($name = '', $prefix = '', $config = Array)

    This occurs because the function definitions do not match the parent class. There is a parent class which defines getModel with 3 arguments. This has been extended by the code you posted which defines getModel with just two arguments.

    The solution is to update the function definition to match the parent. This will make the error go away but would also possibly mis-lead future developers who may expect those extra arguments to have an effect or use the function in a way it wasn't intended; At least try to mitigate this by using ominous argument names:

    public function getModel($name = 'Submission', $prefix = 'AwardAdminModel', $unused = array()) 
    {
        $model = parent::getModel($name, $prefix, array('ignore_request' => true));
        return $model;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?