最近嘗試直接把 joomla3 升級到 PHP8的環境
發覺PHP7的很多寫法真的很容易出包
就是發現在寫入DB資料時候
例如
$row = JTable::getInstance('KKItem', 'Table');
$row->store()
$row 會莫名其妙多出 user 欄位
然後查了好久才發現是前面讀取 user 時候
欄位居然暫存在 Table的getFields了
而且明明PHP7是沒有這問題的
無言
在 joomla3\libraries\src\Table\Table.php 修改
public function getFields($reload = false)
{
static $cache = null; #----->>>>>>> 必須改成 $cache = null; 就是不用 cache
if ($cache === null || $reload)
{
// Lookup the fields for this table only once.
$name = $this->_tbl;
$fields = $this->_db->getTableColumns($name, false);
if (empty($fields))
{
throw new \UnexpectedValueException(sprintf('No columns found for %s table', $name));
}
$cache = $fields;
}
return $cache;
}
修改後寫入就正常了

其實照理說應該是要升級joomla3 升級上去
現在甚至是 joomla 6 了
但是如果升級 joomla
我的整個套件都需要重新寫
更麻煩
所以目前就是針對BUG去改
反正我就只需要 新增修改刪除 這些簡單功能
其他就暫時用不到了

留言板
歡迎留下建議與分享!希望一起交流!感恩!