Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 15 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.



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
see my answer here->… – easy coder Feb 8 at 10:56

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

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 '15 at 21:28

//Get the full URL for sharing purposes

$uri = JUri::current();
echo $uri;
share|improve this answer

Your Answer


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.