【问题标题】:Joomla PHP error within page content页面内容中的 Joomla PHP 错误
【发布时间】:2012-03-28 05:07:48
【问题描述】:

警告:showBlogSection() 的参数 3 应为参考,值在 /home/smartsta/public_html/includes/Cache/Lite/Function.php 第 100 行中给出

我的 Joomla 网站的内容区域突然出现上述错误,有什么建议吗?

更新: 在 godaddy ftp 文件目录、ftp 或 Joomal C-panel 中找到对已定义文件和目录的访问权限没有这样的运气。 在 FTP 中,我无法访问此特定文件来调查第 100 行的内容。 在 Joomla 面板中,在全局配置中,我能够将“错误消息”切换为无,以便至少隐藏此错误。在缓存目录中,我看不到任何进入该文件夹的选项,尽管它显示。 我还在那个 c 面板屏幕的底部看到了这个,但只是链接到一个 joomla 帮助站点,在字段中我没有看到描述的区域来切换“打开或关闭” “遵循 PHP 服务器设置对于安全性来说不是最佳的,建议更改它们: PHP register_globals 设置为ON 而不是OFF "

Update2!:

我找到了有问题的文件,下面是代码。第 100 行仅声明:

全局 $$object_123456789;

application/x-httpd-php Function.php PHP脚本文本

<?php

/**
* This class extends Cache_Lite and can be used to cache the result and output of functions/methods
*
* This class is completly inspired from Sebastian Bergmann's
* PEAR/Cache_Function class. This is only an adaptation to
* Cache_Lite
*
* There are some examples in the 'docs/examples' file
* Technical choices are described in the 'docs/technical' file
*
* @package Cache_Lite
* @version $Id: Function.php 47 2005-09-15 02:55:27Z rhuk $
* @author Sebastian BERGMANN <sb@sebastian-bergmann.de>
* @author Fabien MARTY <fab@php.net>
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

require_once( $mosConfig_absolute_path . '/includes/Cache/Lite.php' );

class Cache_Lite_Function extends Cache_Lite
{

    // --- Private properties ---

    /**
    * Default cache group for function caching
    *
    * @var string $_defaultGroup
    */
    var $_defaultGroup = 'Cache_Lite_Function';

    // --- Public methods ----

    /**
    * Constructor
    *
    * $options is an assoc. To have a look at availables options,
    * see the constructor of the Cache_Lite class in 'Cache_Lite.php'
    *
    * Comparing to Cache_Lite constructor, there is another option :
    * $options = array(
    *    (...) see Cache_Lite constructor
    *    'defaultGroup' => default cache group for function caching (string)
    * );
    *
    * @param array $options options
    * @access public
    */
    function Cache_Lite_Function($options = array(NULL))
    {
        if (isset($options['defaultGroup'])) {
            $this->_defaultGroup = $options['defaultGroup'];
        }
        $this->Cache_Lite($options);
    }

    /**
    * Calls a cacheable function or method (or not if there is already a cache for it)
    *
    * Arguments of this method are read with func_get_args. So it doesn't appear
    * in the function definition. Synopsis :
    * call('functionName', $arg1, $arg2, ...)
    * (arg1, arg2... are arguments of 'functionName')
    *
    * @return mixed result of the function/method
    * @access public
    */
    function call()
    {
        $arguments = func_get_args();
        $id = serialize($arguments); // Generate a cache id
        if (!$this->_fileNameProtection) {
            $id = md5($id);
            // if fileNameProtection is set to false, then the id has to be hashed
            // because it's a very bad file name in most cases
        }
        $data = $this->get($id, $this->_defaultGroup);
        if ($data !== false) {
            $array = unserialize($data);
            $output = $array['output'];
            $result = $array['result'];
        } else {
            ob_start();
            ob_implicit_flush(false);
            $target = array_shift($arguments);
            if (strstr($target, '::')) { // classname::staticMethod
                list($class, $method) = explode('::', $target);
                $result = call_user_func_array(array($class, $method), $arguments);
            } else if (strstr($target, '->')) { // object->method
                // use a stupid name ($objet_123456789 because) of problems when the object
                // name is the same as this var name
                list($object_123456789, $method) = explode('->', $target);
                global $$object_123456789;
                $result = call_user_func_array(array($$object_123456789, $method), $arguments);
            } else { // function
                $result = call_user_func_array($target, $arguments);
            }
            $output = ob_get_contents();
            ob_end_clean();
            $array['output'] = $output;
            $array['result'] = $result;
            $this->save(serialize($array), $id, $this->_defaultGroup);
        }
        echo($output);
        return $result;
    }

}

?>

【问题讨论】:

  • 当您查看第 100 行的 /home/smartsta/public_html/includes/Cache/Lite/Function.php 时,您会看到什么?而且您应该只记录错误而不是显示它们,这样它们就不会出现在 页面中。
  • 我还没有签出文件,但是在这个“突然出现的错误”之前,代码中没有任何问题。有没有可能在所说的第 100 行出现一些东西?如何记录错误以使其不出现在页面中?
  • 当然感谢您的回复!
  • 查看 PHP 手册,例如PHP Error Logging - 在这个网站上,所有突然出现的错误都被归为一类,它们会突然消失,不需要任何答案(和问题)。请参阅常见问题解答,该站点是关于您对某些代码的特定问题。如果你不能明确你的问题是什么,你的问题就太宽泛了——blog.stackoverflow.com/2010/10/asking-better-questions

标签: php joomla warnings


【解决方案1】:

这并不完全是一个错误。这是一个警告

突然?也许您已经升级/更新了您的 PHP 版本。或者将 PHP 配置更改为“严格模式”。

消息“应该是一个引用,给定值”表示被调用的函数应该接收一个引用,而不是一个。看:

$something = 9;
show_section($something);
// here you are passing a variable
// this will be accepted as a reference

show_section(9);
// here you are NOT passing a reference
// here you are passing a VALUE

当你通过“按引用”传递时,函数可以改变变量值......在上面的例子中:

function show_section(&$parameter) {
    $parameter = 'changed!';
}
  1. 注意 $parameter 之前的 & 符号 &amp; - 这就是我们如何指定需要 REFERENCE 的函数。

  2. 在函数调用之后,在上面的示例中,变量$something 的值将是changed! 字符串。


引发错误的行不是“全局”行。是下一个:

$result = call_user_func_array(array($$object_123456789, $method), $arguments);

这里的问题是该函数是通过使用“call_user_func_array”函数间接调用的。

解决方案是将所有参数转换为引用。建议:

foreach ($arguments as $count => $value)
{
    $param = 'param' . $count;
    $$param = $value;
    $arguments[$count] = &$$param;
}

将上面的代码放在call函数的开头,之后下面一行:

$id = serialize($arguments);

试试这个!

【讨论】:

  • 非常感谢您的回复并帮助我理解。您对解决方案有什么建议吗?
  • @cam77:刚刚添加了一个解决方案 - 我认为它有效...... :) 请测试
  • 这个解决方案也对我有用。在将客户的旧信息 Joomla 1.0 站点从退役的 EL4 服务器转移到 EL6 后,问题就开始了。 Joomla's version compatibility page 说 5.2+ 有效,但我忽略了关于只有 Joomla v1.5.15+ 兼容 PHP 5.3 的脚注。感谢您为我节省了数小时的挫败感。
猜你喜欢
  • 2010-10-19
  • 2013-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-18
  • 2016-03-25
  • 2017-11-22
相关资源
最近更新 更多