Skip to content

PHPStorm (Meta) Issues

Mark Sch edited this page Jan 6, 2021 · 6 revisions

Maybe those will be solved soon...

get('Foo') on a child class

// behaviors() = BehaviorRegistry class (extending ObjectRegistry which has that method)
$foo = $this->behaviors()->get('Foo');
// returns mixed instead of \App\Model\Behavior\Foo

I would expect the meta file to be valid, as extension allows us to use the parent's "get" method.

Here is the non-working meta file:

	override(
		\Cake\ORM\BehaviorRegistry::get(0),
		map([
			'Foo' => \App\Model\Behavior\FooBehavior::class,
		])
	);

Using \Cake\Core\ObjectRegistry::get(0) directly works, by the way. But since that is too generic, we have collisions here for the "Foo" string, so this is not applicable.

Fix for now: Use magic property instead

Property access works because of the CodeCompletion file:

$foo = $this->behaviors()->Foo;
// Correct return type
Clone this wiki locally