複数のインターフェイスを実装する際のメソッド名衝突<?php interface Interface1 { public function foo(); public function bar(); } interface Interface2 { public function bar(); } class Class1 implements Interface1,Interface2 { public function foo() {} public function bar() {} } ↓これを実行するとbar()が衝突する。つまり、PHPのインターフェイスは多重継承っぽく使う場合のメソッド名衝突回避にはならないという事? PHP Fatal error: Can't inherit abstract function Interface2::bar() (previously declared abstract in Interface1) in /home/taro/tmp/Class1.php on line 9 ↓ちなみにJavaやC#だとOK。 interface Interface1 { void foo(); void bar(); } interface Interface2 { void bar(); } public class Class1 implements Interface1, Interface2 { public static void main( String args[] ) { } public void foo() { } public void bar() { } } interface Interface1 { void foo(); void bar(); } interface Interface2 { void bar(); } class Class1 : Interface1, Interface2 { [STAThread] static void Main(string[] args) { } public void foo() {} public void bar() {} } 参考 |
|