|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-04-15 13:31 UTC] jpauli@php.net
[2015-04-15 14:00 UTC] jpauli@php.net
-Status: Open
+Status: Not a bug
[2015-04-15 14:00 UTC] jpauli@php.net
[2015-04-15 14:01 UTC] jpauli@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 05:00:01 2025 UTC |
Description: ------------ Consider a class that implements an interface, thereby requiring a public method, and that inherits a protected or private implementation of that method from a base class. Normally it is possible to extend the visibility of the inherited method by overriding it with a public method of the same name that simply defers the call to parent::method(). However if this overriding method is imported from a trait, PHP issues a fatal error complaining that the visibility of the method in the base class is insufficient to meet the requirements of the interface. Removing the interface requirement from the class and using Reflection shows that it successfully imports the public method from the trait and overrides the protected/private inherited method, so the bug must be in the checking for consistency with the interface. The line on which the error is reported is the line that contains the opening brace of the class definition that throws the error. Test script: --------------- interface IReadOnlyObject { public function GetValue(); } interface IWritableObject extends IReadOnlyObject { public function SetValue($value); } trait ReadOnlyObjectMethods { private $value = null; public function GetValue() { return $this->value; } protected function SetValue($value) { $this->value = $value; } } trait WritableObjectMethods { public function SetValue($value) { parent::SetValue($value); } } class ReadOnlyObject implements IReadOnlyObject { use ReadOnlyObjectMethods; } class WritableObject extends ReadOnlyObject implements IWritableObject { use WritableObjectMethods; } $o = new WritableObject(); $o->SetValue('hello'); echo $o->GetValue(); Expected result: ---------------- hello Actual result: -------------- Fatal error: Access level to ReadOnlyObject::SetValue() must be public (as in class IWritableObject) in test.php on line 42