-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Result of a method call on Eloquent\Builder depends on the method casing used #48825
Comments
We'd welcome PRs for this 👍 thanks! |
Thank you for reporting this issue! As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub. If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team. Thank you! |
I've come across the same issue, and I appreciate you bringing this up and suggesting a fix by modifying the case. While this proposal may address the problem at hand, I believe employing a pipeline to manage the |
…ould be case-insensitive Fixes: laravel#48825
…ould be case-insensitive Fixes: laravel#48825
@driesvints I went ahead and implemented a fix in: #48852 |
@Guxinpei While I agree that the current method dispatch could be made more robust, I am not sure if the added complexity would really be worth it.
|
…ould be case-insensitive Fixes: laravel#48825
…ould be case-insensitive Fixes: laravel#48825
…ould be case-insensitive Fixes: laravel#48825
…ould be case-insensitive Fixes: laravel#48825
…ould be case-insensitive (#48852) * fix(Eloquent/Builder): calling the methods on passthru base object should be case-insensitive Fixes: #48825 * Update Builder.php --------- Co-authored-by: Taylor Otwell <[email protected]>
…ould be case-insensitive (#48852) * fix(Eloquent/Builder): calling the methods on passthru base object should be case-insensitive Fixes: laravel/framework#48825 * Update Builder.php --------- Co-authored-by: Taylor Otwell <[email protected]>
Any existing $passthru lists with correct casing will be broken with this update. See my comment on the PR #48852 |
Laravel Version
10.29.0
PHP Version
8.1.2
Database Driver & Version
Not relevant but just in case: psql (PostgreSQL) 14.9 (Ubuntu 14.9-0ubuntu0.22.04.1)
Description
When calling a method on a instance of
Eloquent\Builder
, the result of the method will depend on the method casing used. I discovered this when I called$query->toSQL()
instead of$query->toSql()
and got back aBuilder
instead of astring
which I expected. Given that PHP is case-insensitive about method names, I find this behavior surprising.According to my understanding, the issue happens on this line:
framework/src/Illuminate/Database/Eloquent/Builder.php
Line 1967 in 98ffb75
The
Builder
decides what to do with the result depending on whether the called method is found in the$passthru
property. SincetoSql
is there, andtoSQL
is not, the result is different.I believe the behavior could be fixed by lowercasing the method name and making the
$passthru
property contain lowercased method names, but I am not sure what kind of implications that might have down the road.If needed, I would be happy to volunteer some time into fixing this issue, or reviewing the fix. Either way, thank you for all the hard work on making Laravel so great for the rest of us!
Steps To Reproduce
The behavior can be triggered by the following snippet:
A small repository demonstrating this behavior can be found here:
It's based on the example Laravel app with a separate commit demonstrating the potential problem
The text was updated successfully, but these errors were encountered: