Skip to content

Replace initializer closures with anonymous classes + interfaces #334

@Ocramius

Description

@Ocramius

Initializers are quick to write, but very complex to maintain and refactor, since no explicit contract is provided.

Luckily, since PHP 7, it is possible to simply use anonymous classes.

What we can do is providing a decent interface for initializers now:

interface GhostObjectInitializer
{
    public function __invoke(
        LazyLoadingGhostObject $proxy,
        ?GhostObjectInitializer $initializer,
        array $properties
    ) : bool;
}

Consumers can then use an anonymous class to instantiate such an initializer inline, but would still retain the BC and refactoring advantages of the stronger type hinting.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions