?
avatar Robdebert
Robdebert
25 Aug 2017

Steps to reproduce the issue

Write your own component, or put the following code somewhere in the template, to execude it:

<?php
jimport( 'joomla.application.application' ); 
JApplication::redirect("index.php?anyparameterhere");
exit;
?>

Expected result

Should redirect the browser to the new url

Actual result

in the backend (template: isis) gives the error "using $this when not in object context".

System information (as much as possible)

I activated DEBUG and got this last line:
JROOT\libraries\legacy\application\application.php:380
There is this code:
if (count($this->_messageQueue))

Additional comments

When using JApplication without instanziating it as new class, this error is produced.
Perhaps this line 380 in libraries\legacy\application\application.php should be altered to check, if $this is an object, or use self::_messageQueue instead?

Or even better: give a more detailed error-message to the user, that says "Japplication cannot be used statically here, make an object first or use JFactory::getApplication"

avatar Robdebert Robdebert - open - 25 Aug 2017
avatar joomla-cms-bot joomla-cms-bot - change - 25 Aug 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 25 Aug 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 25 Aug 2017
Category Libraries
avatar mbabker mbabker - change - 25 Aug 2017
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-08-25 11:35:59
Closed_By mbabker
avatar mbabker mbabker - close - 25 Aug 2017
avatar mbabker
mbabker - comment - 25 Aug 2017

Since the method declaration doesn't contain the "static" keyword, it should be expected that a static method call wouldn't work correctly here. You're also getting a PHP generated message, not something Joomla is emitting.

Closing as expected PHP language behavior.

avatar kosmodisk
kosmodisk - comment - 27 Jul 2020

Having the same problem. I think what was really asked here, was how is the proper way to call this redirect, not PHP basics. I would appreciate if you could show how to fix it or at least give a link to "Joomla breaking changes for version XXX->YYY" where this functionality was changed.

avatar kosmodisk
kosmodisk - comment - 27 Jul 2020

I think I found fix. Replace:

JApplication::redirect(...);

with

use Joomla\CMS\Application\CMSApplication;
(CMSApplication::getInstance('site'))->redirect(...);
avatar Fedik
Fedik - comment - 27 Jul 2020

I think I found fix

That is wrong fix. Use:

Joomla\CMS\Factory\Factory::getApplication()->redirect();

Add a Comment

Login with GitHub to post a comment