cakephp icon indicating copy to clipboard operation
cakephp copied to clipboard

6.0 - RFC - Remove argument overloading

Open ADmad opened this issue 1 year ago • 4 comments

Description

We have various methods where argument overloading is used for ease of use. For e.g. for RouteBuilder::scope() if the 2nd argument is a callback it's used as the 3rd argument.

The availability of named arguments and autocompleting features of today's IDEs negate the need of such loading. Removing the overloading would make the API cleaner.

Functions list

  • [ ] RouteBuilder::scope(string $path, Closure|array $params, ?Closure $callback = null)
  • [ ] RouteBuilder::resources(string $name, Closure|array $options = [], ?Closure $callback = null)
  • [ ] RouteBuilder::prefix(string $name, Closure|array $params = [], ?Closure $callback = null)
  • [ ] RouteBuilder::plugin(string $name, Closure|array $params = [], ?Closure $callback = null)
  • [x] Entity::set(array|string $field, mixed $value = null, array $options = [])

CakePHP Version

6.0

ADmad avatar Oct 30 '24 08:10 ADmad

So be clear, you just want to add extra arguments with defaults?

othercorey avatar May 31 '25 13:05 othercorey

For most cases no extra args are needed. For e.g. only need to remove the possibility of passing value of 3rd argument at 2nd position. It was a convenience no longer required with the advent of named args.

ADmad avatar May 31 '25 13:05 ADmad

It would be ideal to have rector rules to help with updating application and plugin logic for these changes.

markstory avatar May 31 '25 23:05 markstory

It would be ideal to have rector rules to help with updating application and plugin logic for these changes.

Summoning our rector champion @LordSimal 😄

ADmad avatar Jun 01 '25 06:06 ADmad

I'm not fond of all the overloaded signatures in CakePHP, but going overboard with named arguments won't improve the API for me since I write application code in Haxe, which does not have a clean way to output code with such function calls.

PaulPatat avatar Oct 10 '25 09:10 PaulPatat