Bug #74488 [Com]: Just flat wrong: "Warning: Declaration of * should be compatible with"

From: Date: Sat, 22 Apr 2017 12:23:59 +0000
Subject: Bug #74488 [Com]: Just flat wrong: "Warning: Declaration of * should be compatible with"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208713@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 Comment by: spam2 at rhsoft dot net Reported by: appacc2040 at gmail dot com Summary: Just flat wrong: "Warning: Declaration of * should be compatible with" Status: Not a bug Type: Bug Package: Compile Warning PHP Version: 7.1.4 Block user comment: N Private report: N New Comment: At least give us "somekeyword_stating_dontmatter class extends parent_class" Previous Comments: ------------------------------------------------------------------------ [2017-04-22 12:15:24] spam2 at rhsoft dot net No they are not because when someone wants Java then he can use Java And that in case of return types the warning becomes a fatal error is a typical php inconsistency like soap extension, require and call to disabled functions not throwing throwable exceptions ------------------------------------------------------------------------ [2017-04-22 11:58:39] nikic@php.net You might find these helpful: https://en.wikipedia.org/wiki/Liskov_substitution_principle https://en.wikipedia.org/wiki/Composition_over_inheritance ------------------------------------------------------------------------ [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 (#208713) next »