YanoRyuichi.com/
Wiki
Blog
GitHub
Sandbox
開始行:
* 複数のインターフェイスを実装する際のメソッド名衝突 [#q3...
#sh(php){{
<?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 Interf...
in /home/taro/tmp/Class1.php on line 9
↓ちなみにJavaやC#だとOK。
#sh(java){{
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() { }
}
}}
#sh(csharp){{
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() {}
}
}}
** 参考 [#ab2d676e]
http://www.php.net/manual/ja/language.oop5.interfaces.php
終了行:
* 複数のインターフェイスを実装する際のメソッド名衝突 [#q3...
#sh(php){{
<?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 Interf...
in /home/taro/tmp/Class1.php on line 9
↓ちなみにJavaやC#だとOK。
#sh(java){{
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() { }
}
}}
#sh(csharp){{
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() {}
}
}}
** 参考 [#ab2d676e]
http://www.php.net/manual/ja/language.oop5.interfaces.php
ページ名: