安装Joomla扩展JCH后出现非对象属性获取通知的技术问询
What's the Issue?
After installing the JCH extension, you're seeing this PHP notice pop up:
Notice: Trying to get property of non-object in ../libraries/src/UCM/UCMType.php on line 169
The Good News First
Per the JCH extension developer, this is not a problem with the JCH extension itself—it's a small quirk in Joomla's core code. Even better: it won't affect how the JCH extension functions at all.
Why This Happens
Let's break down the problematic code. The error hits on line 169 of UCMType.php:
$tableNameFromType = $tableFromType->special->prefix . $tableFromType->special->type;
Here's the full surrounding function context:
public function getTypeByTable($tableName) { $query = $this->db->getQuery(true); $query->select('ct.*'); $query->from($this->db->quoteName('#__content_types', 'ct')); // $query->where($this->db->quoteName('ct.type_alias') . ' = ' . (int) $typeAlias); $this->db->setQuery($query); $types = $this->db->loadObjectList(); foreach ($types as $type) { $tableFromType = json_decode($type->table); $tableNameFromType = $tableFromType->special->prefix . $tableFromType->special->type; if ($tableNameFromType === $tableName) { return $type; } } return false; }
The bug stems from this: json_decode($type->table) might return null or a non-object (if the table field in the #__content_types database table has invalid JSON, or is empty). When that happens, trying to access $tableFromType->special throws the notice because $tableFromType isn't the object the code expects.
How to Handle It
Since this doesn't break your JCH extension, you have two straightforward options:
- Hide the notice (easiest fix): Head to your Joomla backend's Global Configuration, find the "Error Reporting" setting, and set it to "System Default" or "None". This will suppress non-critical PHP notices like this one without affecting functionality.
- Patch the core code (advanced): If you want to fix the root cause, add a validation check right after the
json_decodeline to skip invalid entries:
Note: Modifying Joomla core code means your change will get overwritten when you update Joomla, so the first option is usually the safer choice for most users.// Insert this after $tableFromType = json_decode($type->table); if (!is_object($tableFromType) || !isset($tableFromType->special)) { continue; }
内容的提问来源于stack exchange,提问作者GalanopD

