Description
Referenced RFC #13455
The following code:
<?phpinterface ExampleInterface {} // parentinterface MutableExampleInterface extends ExampleInterface {} // childfinalclass Example implements MutableExampleInterface {} // impl// parent providerinterface ExampleProviderInterface
{
// Any type that implements ExampleInterface can be readpublicExampleInterface$property { get; }
}
// child provider that "overrides" parent definitioninterface MutableExampleProviderInterface extends ExampleProviderInterface
{
// Any type that implements (MutableExampleInterface & ExampleInterface) can be read + write// We supplement the object with the set methodpublicMutableExampleInterface$property { get; set; }
}
// An implementation that uses implementationfinalclass ExampleProvider implements MutableExampleProviderInterface
{
publicExample$property { // << implementation// We can return the implementation, because it implements (MutableExampleInterface & ExampleInterface)
get => $this->property; // Any instance of ExampleInterface is allowed for set, since it satisfies the covariance condition
set (ExampleInterface$v) => $this->property = newExample($v);
}
}Resulted in this output:
Fatal error: Type of ExampleProvider::$property must be MutableExampleInterface (as in class MutableExampleProviderInterface)
But I expected this output instead:
Same code (logic) using getters and setters instead of properties: https://onlinephp.io/c/4e180
interface ExampleInterface {}
interface MutableExampleInterface extends ExampleInterface {}
finalclass Example implements MutableExampleInterface {}
interface ExampleProviderInterface
{
publicfunctiongetProperty(): ExampleInterface;
}
interface MutableExampleProviderInterface extends ExampleProviderInterface
{
publicfunctiongetProperty(): MutableExampleInterface;
publicfunctionsetProperty(MutableExampleInterface$value): void;
}
finalclass ExampleProvider implements MutableExampleProviderInterface
{
publicfunctiongetProperty(): Example {}
publicfunctionsetProperty(ExampleInterface$value): void {}
}Ping @iluuu1994 (again) ^_^
PHP Version
PHP 8.4-beta1
Operating System
No response
Description
Referenced RFC #13455
The following code:
Resulted in this output:
But I expected this output instead:
Same code (logic) using getters and setters instead of properties: https://onlinephp.io/c/4e180
Ping @iluuu1994 (again) ^_^
PHP Version
PHP 8.4-beta1
Operating System
No response