You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
I really don't like the way Blade component methods are invoked without parenthesis when there are no arguments. It feels like such a hack and is inconsistent for a couple of different reasons.
I'm sure it won't change in 7.x now but would love to see it changed in the future to be nicer to use. I'm curious about what other people think too.
Personally I'd like to see one simple (although backwards incompatible) change made: methods always need parenthesis in the Blade template to be invoked.
Here are my reasons for not liking the current behaviour:
1: You can't choose to consistently use parenthesis for methods. Returning a string from the method and then using parenthesis will attempt to call a function with the name of the returned string.
class ExampleComponent extends Component
{
publicfunctionsomething() {
return'somethingElse';
}
publicfunctionrender() {
return'<div {{ $something() }}></div>'; // Triggers: "Call to undefined function somethingElse()"
}
}
2: It's not immediately obvious what'll happen if you have both a property and method of the same name:
3: It's not immediately obvious how you should interact with a method that has a nullable parameter.$something, $something() or $something(null) could all be equally valid in some way, but mean different things in the context of Blade components.
I don't want to have to think so deeply about how I'm using something when it could've just been simplified and behave like normal PHP. Every time I do something with a Blade component now, a chunk of my time goes into considering what behaviour is going to come out of a method.
The text was updated successfully, but these errors were encountered:
I really don't like the way Blade component methods are invoked without parenthesis when there are no arguments. It feels like such a hack and is inconsistent for a couple of different reasons.
I'm sure it won't change in 7.x now but would love to see it changed in the future to be nicer to use. I'm curious about what other people think too.
Personally I'd like to see one simple (although backwards incompatible) change made: methods always need parenthesis in the Blade template to be invoked.
Here are my reasons for not liking the current behaviour:
1: You can't choose to consistently use parenthesis for methods. Returning a string from the method and then using parenthesis will attempt to call a function with the name of the returned string.
2: It's not immediately obvious what'll happen if you have both a property and method of the same name:
3: It's not immediately obvious how you should interact with a method that has a nullable parameter.
$something
,$something()
or$something(null)
could all be equally valid in some way, but mean different things in the context of Blade components.I don't want to have to think so deeply about how I'm using something when it could've just been simplified and behave like normal PHP. Every time I do something with a Blade component now, a chunk of my time goes into considering what behaviour is going to come out of a method.
The text was updated successfully, but these errors were encountered: