“Fatal error: Cannot access protected property ContentViewArticle::$params” Error in Joomla

About 70% of the work we’re doing nowadays is migrating Joomla websites from version 1.5 to version 2.5. A common error that we get while migrating a template is the following:

Fatal error: Cannot access protected property ContentViewArticle::$params

We have seen the above error so many times so far that we now know the solution by heart.

So, how does this problem happen?

Old auto-generated Artisteer templates have a file called functions, which is located in the root directory of the Joomla’s template. Some functions (located in the functions file), such as the artxPageTitle function, try to access protected properties directly, which is technically illegal, and thus returning the above fatal error.

And, how can the problem be solved?

Many websites, even Joomla’s official website, suggest solutions that most likely will not work, or that will work, but will destroy some functionality on the website. This is a bit disappointing, because the solution couldn’t be simpler. Here’s how you can solve the problem:

  • Locate the problematic line (usually the error message will specify which line is that).
  • Check what is the object name trying to access the params property (or attribute). For example, if you have something like $page->params in your code then the object name that you’re looking for is $page.

  • Add the following line in the top of the function that has the problem (assuming the object name is $page):

    jimport( 'joomla.html.parameter' );
    $params = new JParameter($page->get('params'));

  • Replace all occurrences of $page->params with $params in your function. (again, we are assuming that the name of the object trying to access the $params property is $page).

  • That’s it!

A real life example would be the artxPageTitle function which should change from:

function artxPageTitle($page, $criteria = null, $key = null){
	if ($criteria === null)
		$criteria = $page->params->def('show_page_title', 1);
	return $criteria
		? ('<span class="componentheading' . $page->params->get('pageclass_sfx') . '">'
			. $page->escape($page->params->get($key === null ? 'page_title' : $key)) . '</span>')
		: '';
}

to:

function artxPageTitle($page, $criteria = null, $key = null){
	jimport( 'joomla.html.parameter' );
	$params = new JParameter($page->get('params'));

	if ($criteria === null)
		$criteria = $params->def('show_page_title', 1);
	return $criteria
		? ('<span class="componentheading' . $params->get('pageclass_sfx') . '">'
			. $page->escape($params->get($key === null ? 'page_title' : $key)) . '</span>')
		: '';
}

If this post is a bit too technical for you, then that's why we're here for! All you need to do is to contact us and you can rest assured that we'll fix this problem for you in a glimpse and that we won't charge you much!

One Response to ““Fatal error: Cannot access protected property ContentViewArticle::$params” Error in Joomla”
  1. Comment by Alan — July 19, 2013 @ 11:00 pm

    THANK YOU – I have been struggling to upgrade an old Joomla 1.5 template to 2.5. I was almost there and then this problem struck. Your solution saved the day. Thanks again. Brilliant!

Leave a comment