Take the 2-minute tour ×
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It's 100% free, no registration required.

The following code works in Joomla 1.6, but it throws up a Strict Standards error in 3.x:

Strict Standards: Only variables should be assigned by reference

    //Get the full URL for sharing purposes
    $uri = & JFactory::getURI();
    $absolute_url = $uri->toString();

    <?php echo $absolute_url; ?>

How can I get the code to work without the error in Joomla 3.x?

share|improve this question
    
Btw. it doesn't depend on Joomla version but by PHP version. Assigning variables by reference is deprecated in PHP –  turson Sep 2 '14 at 14:02
    
Thanks for the tip –  RustyJoomla Sep 3 '14 at 9:08

2 Answers 2

up vote 8 down vote accepted

Delete the &

//Get the full URL for sharing purposes
$uri = JFactory::getURI();
$absolute_url = $uri->toString();

<?php echo $absolute_url; ?>

With PHP5 the new operator automatically returns a reference, so the '&' is not needed anymore.

From the official PHP manual:

As of PHP 5, the new operator returns a reference automatically, so assigning the result of new by reference results in an E_DEPRECATED message in PHP 5.3 and later, and an E_STRICT message in earlier versions.

source: http://php.net/manual/en/language.operators.assignment.php

UPDATE

FYI I am using this approach to get the current URL:

<?php echo JUri::getInstance(); ?>
share|improve this answer
    
Thanks for your help, can't believe I missed that! –  RustyJoomla Sep 2 '14 at 11:27

According to the Joomla tutorial, you can get the current URL by this function:

JUri::current();
share|improve this answer
    
JUri::current() returns the current request URI without the query or fragment parts. For example, if you visit the following URL: localhost/joomla3/index.php/component/users/?view=remind JUri::current() would return: localhost/joomla3/index.php/component/users –  fruppel Jan 20 at 21:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.