Fix for “Undefined array key” and Fatal TypeError in Nette Reflection
-
Hi everyone,
I encountered the following errors when using the Packeta plugin (which bundles Nette) on my WordPress site.PHP Warning: Undefined array key "Packetery\Module\Framework\WpAdapter" in .../wp-content/plugins/packeta/deps/nette/utils/src/Utils/Reflection.php on line 234
PHP Fatal error: Uncaught TypeError: Packetery\Nette\Utils\Reflection::getUseStatements(): Return value must be of type array, null returned in .../wp-content/plugins/packeta/deps/nette/utils/src/Utils/Reflection.php on line 234Cause:
The issue is in the getUseStatements method of Reflection.php. If the requested class name is not found in the internal cache, the function tries to return a non-existent array key, which triggers the warning. If the key is missing, the function returns null, but it is type-hinted to always return an array, causing a fatal error.
Solution:
Edit the file wp-content/plugins/packeta/deps/nette/utils/src/Utils/Reflection.php and change the last line of the getUseStatements method from:return $cache[$name];to:
return $cache[$name] ?? [];This ensures the function always returns an array, even if the class is not found, preventing both the warning and the fatal error. Hope this helps anyone facing the same issue!
The topic ‘Fix for “Undefined array key” and Fatal TypeError in Nette Reflection’ is closed to new replies.