Created
March 11, 2019 09:42
-
-
Save mugyu/dbf297a544446bbcafa0c56ec21cb5a9 to your computer and use it in GitHub Desktop.
php7: 継承したメソットの引数違いでワーニング
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A | |
{ | |
protected function data(int $id) | |
{ | |
return "A"; | |
} | |
} | |
class B extends A | |
{ | |
protected function data(string $id) | |
{ | |
return parent::data(1); | |
} | |
public function say() { | |
echo $this->data() . "\n"; | |
} | |
} | |
$b = new B(); | |
/* | |
* Warning: Declaration of B::data(string $id) should be compatible with A::data(int $id) | |
* PHP Warning: Declaration of B::data(string $id) should be compatible with A::data(int $id) | |
* | |
* ------- | |
* | |
* php7のバージョンから継承したメソッドの引数の型や数が変わるとワーニングになるらしい。 | |
* 親と子で引数の数が変わるぐらいよくある事だと思ってたけどそうでもないのか? | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment