Skip to content
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

[7.x] Parameterless Component Methods Invokable With & Without Parens #32560

Merged
merged 5 commits into from
Apr 28, 2020

Conversation

taylorotwell
Copy link
Member

@taylorotwell taylorotwell commented Apr 27, 2020

This change allows parameterless Blade component methods to be invoked using no parameters or using parameters:

{{ $foo }}

{{ $foo() }}

It's easy to forget that these methods currently are not able to called with parentheses. I have stumbled on this myself. This should be backward compatible since both ways of echoing the value are supported.

@GrahamCampbell GrahamCampbell changed the title Parameterless Component Methods Invokable With & Without Parens [7.x] Parameterless Component Methods Invokable With & Without Parens Apr 27, 2020
@imliam
Copy link
Contributor

imliam commented Apr 27, 2020

For the record, this fixes a concern brought up in laravel/ideas#2129

I still think this is a backwards-incompatible change. Say we have a function on the Blade component:

public function foo()
{
    return 'bar';
}

Which in turn we used in the Blade with $foo()

Prior to this change, $foo would be evaluated first, executing that public method. The resulting callable ('bar') would then be executed due to the parenthesis at the end - so in turn it would execute bar()

With this change, it would now only execute the foo method and not bar.


I'm not using the former behaviour myself, but still, see it as a breaking change. I like the change and more consistent behaviour myself and would love to see it in 8.x


Edit: I'd also note that this doesn't fix the discrepancy between whether or not $foo is a property or method - you can't tell from the Blade file itself and will run into issues if you have a property and method of the same name

@taylorotwell
Copy link
Member Author

taylorotwell commented Apr 28, 2020

I'm not particularly concerned about that breaking change as I very sincerely doubt anyone is doing that.

@taylorotwell taylorotwell changed the base branch from 7.x to master April 28, 2020 01:09
@taylorotwell taylorotwell changed the base branch from master to 7.x April 28, 2020 01:09
@taylorotwell taylorotwell merged commit e08e184 into 7.x Apr 28, 2020
@taylorotwell taylorotwell deleted the parameterless-callbacks branch April 28, 2020 13:48
driesvints added a commit to laravel/cashier-paddle that referenced this pull request Jun 19, 2020
gregoryross1211 added a commit to gregoryross1211/cashier-paddle-laravel that referenced this pull request Nov 11, 2022
goldentroll added a commit to goldentroll/cashier-paddle that referenced this pull request Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants