-
Notifications
You must be signed in to change notification settings - Fork 89
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
Remove & reference declaration from db_query to avoid warning #870
Conversation
Also adjusts the code that calls the function with a prepended &, as that would have caused a new warning. Fixes #848
@garvinhicking I don't currently understand the idea of the & function declaration. What was the idea here, how could database query results be passed as reference and thus mutated? I assume I'm missing something, this is not my area of expertise. |
Okay, I looked into this a bit more. My research so far: https://www.php.net/manual/en/language.references.return.php shows clearly how this is supposed to work (now). A class variable is shared by returning it as a reference. This example does not apply here, as Why is the code like this? I do not know, but it is at least 19 years old, Serendipity/include/db/mysql.inc.php Line 61 in 80e1434
Will this change have a negative impact? According to my code search in additional_plugins, almost all calls to Second usage is that https://github.com/s9y/additional_plugins/blob/master/emerge_spartacus.php#L22 copies the function declaration, so this would have to be changed later when spartacus is build with a new s9y version. I intend to merge this. It silences a notice, should make the code easier and I do not expect bugs, as the unclear semantics of the reference passing probably made it meaningless in PHP >= 5. I'll give it a few more days for potential feedback though :) |
Is also not returning a sharable variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking care.
Yes, this was a micro optimization to hint PHP at "knowing" it shall not re-create intermediate variables in memory for passing function results around, so no "copy by variable".
PHP8 is so much beyond needing such an optimization so for legibility, this change should be totally fine I believe.
Also adjusts the code that calls the function with a prepended &, as that would have caused a new warning. Fixes #848.