Skip to content

RFC - 6.0 - Drop the proxying of behavior methods through the table instance. #18288

@ADmad

Description

@ADmad

Description

Currently behavior methods like SomeBehavior::foo() can be directly accessed through the table instance, the behavior is attached to, as $table->foo(). While this was a good convenience to have back in the day, it's effectively been made redundant since the availability of traits in PHP.

The feature cause various problems:

  • It adds unnecessary code and checks to proxy the call to the behavior instance when the method is called on the table instance.
  • It hinders static analysis as the tools are unaware of this "magic" and requires either stubs or custom plugins to avoid "method doesn't exist" errors by the tools.
  • It causes issue when trying to reflect a method argument as highlighted here
  • Another issue reported below is comments is using LocatorAwareTrait in two behaviors and load them in the same table triggers a LogicException due to the duplicate methods check in the behavior registry.

So I propose dropping this feature and instead users can use traits.

CakePHP Version

6.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions