title: php - call to a member function on null
body: <p>Apologies if this is <em>real</em> basic, but when PHP gets into functions I'm over my head.</p>
  <p>I have a plug-in for a forum, which loads a flash cookie as a method to detect duplicate accounts.</p>
  <p>The script is failing on about 0.1% of page views, causing a WSOD.  The error points to this line:</p>
  <pre><code>return $this-&gt;registry-&gt;output-&gt;getTemplate( 'dml' )-&gt;duplicatesLoadMovie( $host, $path, $id, $md5 );
  </code></pre>
  <p>The error message is:</p>
  <blockquote>
  <p>Fatal error:  Call to a member function duplicatesLoadMovie() on null in /var/www/.../web/forums/hooks/duplicatesLoadMovie.php on line 75</p>
  </blockquote>
  <p>To me, this reads as one of <code>$host</code>, <code>$path</code>, <code>$id</code>, or <code>$md5</code> is returning <code>null</code>, 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).</p>
  <p>Can I simply do something to the effect of <code>$id = 0 if id.null</code>? (sorry for the Rubyspeak) for each of the <code>$variables</code>?</p>
  <p>Full source of the file:</p>
  <pre><code>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-&gt;registry   = ipsRegistry::instance();
      $this-&gt;settings   =&amp; $this-&gt;registry-&gt;fetchSettings();
      $this-&gt;member     = $this-&gt;registry-&gt;member();
      $this-&gt;memberData =&amp; $this-&gt;registry-&gt;member()-&gt;fetchMemberData();
  }
  
  /**
   * Get the output
   *
   * @access  public
   * @return  @e string
   **/
  public function getOutput()
  {
      /* Grab host URL and installation path of the community */
      $host = $this-&gt;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-&gt;memberData['member_id'] )
      {
          $id = 'mid=' . $this-&gt;memberData['member_id'];
      }
      else
      {
          $id = 'sid=' . $this-&gt;member-&gt;session_id;
      }
  
      /* Grab the secure key for AJAX */
      $md5 = 'md5=' . $this-&gt;member-&gt;form_hash;
  
      /* Finally, call the template bit */
      return $this-&gt;registry-&gt;output-&gt;getTemplate( 'dml' )-&gt;duplicatesLoadMovie( $host, $path, $id, $md5 );
  }
  </code></pre>