Skip to content

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

Merged
taylorotwell merged 5 commits into
7.xfrom
parameterless-callbacks
Apr 28, 2020
Merged

[7.x] Parameterless Component Methods Invokable With & Without Parens#32560
taylorotwell merged 5 commits into
7.xfrom
parameterless-callbacks

Conversation

@taylorotwell

@taylorotwell taylorotwell commented Apr 27, 2020

Copy link
Copy Markdown
Member

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

imliam commented Apr 27, 2020

Copy link
Copy Markdown
Contributor

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

taylorotwell commented Apr 28, 2020

Copy link
Copy Markdown
Member Author

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 pushed a commit to goldentroll/cashier-paddle that referenced this pull request Mar 13, 2023
Because we need the feature from laravel/framework#32560
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