What is the purpose of $forum_id on its own line?

LPH

Well-known member
In looking at this code, why is $forum_id sitting in a line all by itself?

Sorry to be daft but it looks strange to me.

Should it be forum_id=' ' or something else?

PHP:
  if($post->post_type == 'post')
  {
    //get the category for this post
    $categories = get_the_category($post->ID);

    //lookup what forum ID posts of this category go in
    $forum_id;

    $forum_id_array = $XF->options['xf_category_forum_id'];

    foreach($categories as $category)
    {
      $slug = $category->slug;
      if(isset($forum_id_array[$slug]) && $forum_id_array[$slug] != 0)
      {
        $forum_id = $forum_id_array[$slug];
        break;
      }
    }

    if(!isset($forum_id))
    {
      $forum_id = $forum_id_array['default'];
    }

    xf_insert_thread($post, $forum_id);
  }
    else ... blah blah more and more ... blah ..
 
Judging by the code you could remove it with no ill effects. Not sure why it's there, seems like some left over code that should've been removed.
 
Judging by the code you could remove it with no ill effects. Not sure why it's there, seems like some left over code that should've been removed.

OK. I'm going to comment it out on a test environment and see what happens. Thank you. I just didn't know if there was a purpose that I didn't understand.
 
In looking at this code, why is $forum_id sitting in a line all by itself?

Sorry to be daft but it looks strange to me.

Should it be forum_id=' ' or something else?
By declaring the variable you are forcing the php interpreter to assign a pointer, and to set its value to NULL. It is the equivalent of $forum_id = NULL;

It is done, so the subsequent statement of !isset() will return correctly.
 
By declaring the variable you are forcing the php interpreter to assign a pointer, and to set its value to NULL. It is the equivalent of $forum_id = NULL;

It is done, so the subsequent statement of !isset() will return correctly.

Thank you.

If I understand you correctly, you are stating that line is shorthand. Therefore, I searched and found one reference to this shorthand and the post stated it failed. Do you have another reference suggesting that this works as expected?

Update: As soon as I added the = NULL for that variable as well as another one then the WordPress debug bar errors for undefined variables disappeared.
 
Last edited:
By declaring the variable you are forcing the php interpreter to assign a pointer, and to set its value to NULL. It is the equivalent of $forum_id = NULL;

It is done, so the subsequent statement of !isset() will return correctly.

Wouldn't !isset() return correctly whether that line was there or not..?
 
Top Bottom