Bug #74488 [Opn->Nab]: Just flat wrong: "Warning: Declaration of * should be compatible with"

From: Date: Sat, 22 Apr 2017 11:58:41 +0000
Subject: Bug #74488 [Opn->Nab]: Just flat wrong: "Warning: Declaration of * should be compatible with"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208711@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74488&edit=1 ID: 74488 Updated by: nikic@php.net Reported by: appacc2040 at gmail dot com Summary: Just flat wrong: "Warning: Declaration of * should be compatible with" -Status: Open +Status: Not a bug Type: Bug Package: Compile Warning PHP Version: 7.1.4 Block user comment: N Private report: N New Comment: You might find these helpful: https://en.wikipedia.org/wiki/Liskov_substitution_principle https://en.wikipedia.org/wiki/Composition_over_inheritance Previous Comments: ------------------------------------------------------------------------ [2017-04-22 11:52:33] appacc2040 at gmail dot com Description: ------------ "Warning: Declaration of * should be compatible with" In the real world abstracted features work this way all the time. This warning is an arbitrary and artificial idea that has no basis in the real world. PHP Warning: Declaration of combinationLock::unlock($combination) should be compatible with abstractLock::unlock() in test.php on line 23 PHP Warning: Declaration of paddleLock::unlock($key) should be compatible with abstractLock::unlock() in test.php on line 32 Test script: --------------- <?php class abstractLock { private $locked = true; public function unlock() { $this->locked=false; } public function lockStatus() { if($this->locked) return "Locked\n"; else return "Unlocked\n"; } } class combinationLock extends abstractLock { private $combination = '32-10-21'; // combination public function unlock($combination) // unlock WITH combination { if($this->combination == $combination) parent::unlock(); } } class paddleLock extends abstractLock { private $key = '100,70,80,30,50,90,60,40,100'; // ridge heights public function unlock($key) // unlock WITH key { if($this->key == $key) parent::unlock(); } } $lock1 = new paddleLock(); echo "paddleLock is " . $lock1->lockStatus(); $lock1->unlock('100,70,80,30,50,90,60,40,100'); echo "paddleLock is " . $lock1->lockStatus(); $lock2 = new combinationLock(); echo "combinationLock is " . $lock2->lockStatus(); $lock2->unlock('32-10-21'); echo "combinationLock is " . $lock2->lockStatus(); ?> Expected result: ---------------- No warning about things that happen all the time in the real world. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74488&edit=1

« previous php.bugs (#208711) next »