# PHP Fatal error: Only variables can be passed by reference

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bill127300
Forum Newbie
Posts: 3
Joined: Fri Feb 13, 2009 9:38 am

# PHP Fatal error: Only variables can be passed by reference

Post by bill127300 »

I need help making my wordpress site work. When I visit the blog page I get this error:

#
PHP Fatal error: Only variables can be passed by reference in D:\Program Files\Ensim\WEBppliance\SiteData\Domains\doverma.org\ROOT\Inetpub\wwwroot\wordpress\wp-includes\query.php on line 2548


Line 2548 on that page says:

Code: Select all

 
$this->queried_object = & get_page(get_option('page_for_posts'));
 
Here's a snippet of all the code in that area of the page in case you need to see more than that one line:

Code: Select all

 
} else if ($this->is_tax) {
            $tax = $this->get('taxonomy');
            $slug = $this->get('term');
            $term = &get_terms($tax, array('slug'=>$slug));
            if ( is_wp_error($term) || empty($term) )
                return NULL;
            $term = $term[0];
            $this->queried_object = $term;
            $this->queried_object_id = $term->term_id;
        } else if ($this->is_posts_page) {
            $this->queried_object = & get_page(get_option('page_for_posts'));
            $this->queried_object_id = (int) $this->queried_object->ID;
        } else if ($this->is_single) {
            $this->queried_object = $this->post;
            $this->queried_object_id = (int) $this->post->ID;
        } else if ($this->is_page) {
            $this->queried_object = $this->post;
            $this->queried_object_id = (int) $this->post->ID;
        } else if ($this->is_author) {
            $author_id = (int) $this->get('author');
            $author = get_userdata($author_id);
            $this->queried_object = $author;
            $this->queried_object_id = $author_id;
 
Any help in fixing this is greatly appreciated as I have no idea how to code stuff on my own so I don't know whats going on.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: # PHP Fatal error: Only variables can be passed by reference

Post by Mark Baker »

get_option('page_for_posts') isn't a variable, it's a function call that returns a value.
The get_page function is expecting a parameter passed by reference rather than passed by value, presumably because it is going to make some changes to that value that you can then subsequently access.

Code: Select all

 
$tmpPageVariable = get_option('page_for_posts');
$this->queried_object = & get_page($tmpPageVariable);
 
echo or log $tmpPageVariable immediately before and after the call to get_page() so that you can see what change has been made
bill127300
Forum Newbie
Posts: 3
Joined: Fri Feb 13, 2009 9:38 am

Re: # PHP Fatal error: Only variables can be passed by reference

Post by bill127300 »

Mark Baker wrote:get_option('page_for_posts') isn't a variable, it's a function call that returns a value.
The get_page function is expecting a parameter passed by reference rather than passed by value, presumably because it is going to make some changes to that value that you can then subsequently access.

Code: Select all

 
$tmpPageVariable = get_option('page_for_posts');
$this->queried_object = & get_page($tmpPageVariable);
 
echo or log $tmpPageVariable immediately before and after the call to get_page() so that you can see what change has been made
I'd love to do whatever it is you just said if it will help me but all I heard was blabbity blah blabbity blah something hard. Is it at all possible to dumb that down? I barely know what php is nevermind how to do anything with it. I'd appreciate spelling that out real slow for this dumby.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: # PHP Fatal error: Only variables can be passed by reference

Post by Mark Baker »

bill127300 wrote:I'd love to do whatever it is you just said if it will help me but all I heard was blabbity blah blabbity blah something hard. Is it at all possible to dumb that down?
OK simple answer
Replace the single line that says

Code: Select all

$this->queried_object = & get_page(get_option('page_for_posts'));
with the two lines

Code: Select all

$tmpPageVariable = get_option('page_for_posts');
$this->queried_object = & get_page($tmpPageVariable);
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: # PHP Fatal error: Only variables can be passed by reference

Post by Eran »

Shouldn't that be:

Code: Select all

$tmpPageVariable = get_page(get_option('page_for_posts'));
$this->queried_object = & $tmpPageVariable;
bill127300
Forum Newbie
Posts: 3
Joined: Fri Feb 13, 2009 9:38 am

Re: # PHP Fatal error: Only variables can be passed by reference

Post by bill127300 »

YOUUUU ROOOCKK. Thank you so much. Worked perfectly.
Post Reply