-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$db->loadObjectList('id', MenuItem::class) fails on Unknown fetch type '8' #254
Comments
The error happens here: https://github.com/joomla-framework/database/blob/2.0.0/src/Mysqli/MysqliStatement.php#L542-L546 And this is how it is handled in a couple of other drivers: https://github.com/joomla-framework/database/blob/2.0.0/src/Pdo/PdoStatement.php#L177 So it looks like |
This is by design. You are better off not using the custom object mode, and the project would be best off deprecating this mode completely from the database API in favor of a data mapping layer to handle mapping database results into PHP class objects. |
Thank you for your response; it makes sense and I have already stopped using the custom objects in my code. Though your response raises a few questions:
Personally, I have used PDO the whole time and the issue was only found recently because of that. |
Just for reference, this GitHub org is the only Joomla owned org I can comment in (and I’d rather leave it this way; it’s better for most people, myself included, that I can’t post in the more visible Joomla repos). To my recollection, MySQLi is more readily available in a traditional cPanel based setup than PDO is. Hence, the CMS defaulting to it. I generally don’t pay attention to the defaults as I roll new PHP support out on the WHM/cPanel servers I maintain, but it may very well be that PDO is as readily available these days and that it could be considered as the default for a future version. That should be a data driven decision though IMO. As for improving the error message, as we always say in our various OSS spaces, “pull requests welcome”. Admittedly if I were writing the code today I would’ve used an exception based on that exact scenario, but 2017 me wasn’t doing a lot of “throw Exception with specialized message” types of things. As for deprecations, that’s on the current technical leads to decide. I would advocate for deprecation of custom object fetching in full since that mode is the most problematic as it relates to a database abstraction layer and creating a cross-platform portable application, and that the generally accepted practice for handling custom objects is through some sort of data mapping layer (whether it’s a full blown ORM or hidden away in an Active Record style implementation like the CMS’ Table class or the Entities Framework package). But, custom objects were always supported through the API and I didn’t want to make any bigger B/C breaks than necessary while refactoring the database driver internals, so I did leave it in place for the drivers where it would reliably work (all of them minus MySQLi and that’s only because of the differences if |
Steps to reproduce the issue
This example needs Joomla, see issue joomla/joomla-cms#35452
Expected result
The query should work just as it worked in Joomla 3.9/3.10.
Actual result
Exception:
Unknown fetch type '8'
. This seems to happen when usingmysqli
but not when usingdbo
.Type 8 is same as
FetchMode::CUSTOM_OBJECT
.System information (as much as possible)
PHP 8.0.10 / 7.4.23
Additional comments
Following workaround works (replace the last line):
The text was updated successfully, but these errors were encountered: