duanqiang2617 2015-08-04 04:27
浏览 39
已采纳

php - 在null上调用成员函数

Apologies if this is real basic, but when PHP gets into functions I'm over my head.

I have a plug-in for a forum which loads a flash cookie as a method to detect duplicate accounts.

The script is failing on about 0.1% of page views, causing a WSOD. The error points to this line:

return $this->registry->output->getTemplate( 'dml' )->duplicatesLoadMovie( $host, $path, $id, $md5 );

and the error is:

Fatal error: Call to a member function duplicatesLoadMovie() on null in /var/www/.../web/forums/hooks/duplicatesLoadMovie.php on line 75

To me, this reads as one of $host, $path, $id, or $md5 is returning null, but as this is not my script (and the coder is, of course, unresponsive), I would like to fix this in the simplest way possible (other than removing it, which is the fallback position).

Can I simply do something to the effect of $id = 0 if id.null? (sorry for the Rubyspeak) for each of the $variables?

Full source of the file:

class duplicatesLoadMovie
{ 
/**
 * Registry object shortcuts
 *
 * @var     $registry
 * @var     $settings
 * @var     $member
 * @var     $memberData
 **/
public $registry;
public $settings;
public $member;
public $memberData;

/**
 * Main function executed automatically by the controller
 *
 * @access  public
 * @return  @e void
 **/
public function __construct()
{
    $this->registry   = ipsRegistry::instance();
    $this->settings   =& $this->registry->fetchSettings();
    $this->member     = $this->registry->member();
    $this->memberData =& $this->registry->member()->fetchMemberData();
}

/**
 * Get the output
 *
 * @access  public
 * @return  @e string
 **/
public function getOutput()
{
    /* Grab host URL and installation path of the community */
    $host = $this->settings['board_url'];

    $parsed = parse_url( $host );
    $path = trim( $parsed['path'], '/' );
    if( $path == '' )
    {
        $path = '/';
    }

    $host = 'host=' . $host;
    $path = 'path=' . $path;

    /* Determine the appropriate identification method (member_id for members and session_id for guests) */
    if( $this->memberData['member_id'] )
    {
        $id = 'mid=' . $this->memberData['member_id'];
    }
    else
    {
        $id = 'sid=' . $this->member->session_id;
    }

    /* Grab the secure key for AJAX */
    $md5 = 'md5=' . $this->member->form_hash;

    /* Finally, call the template bit */
    return $this->registry->output->getTemplate( 'dml' )->duplicatesLoadMovie( $host, $path, $id, $md5 );
}
  • 写回答

1条回答 默认 最新

  • douhao1956 2015-08-04 04:36
    关注

    I'd suspect that this getTemplate( 'dml' ) is not returning a value. If you do a var_dump(getTemplate( 'dml' )), does it show anything?

    You might check for "null" before doing that line of code, and in your "else" statement, output an error message, or some other action suitable for that error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染