This warning has nothing to do with the real world. Forget the academic examples and look at a real world example. There are 1000's of LOCK manufacturers that make a door lock with a combination touchpad and a key override. Do they use 2 deadbolts - one for the combination lock and one for the key lock? NO. The deadbolt lock is abstracted to the key lock and the combination lock. That's REAL WORLD. PHP ( who will quickly reject any bug reports on this subject) want to stick their heads in the sand on this.
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();
PHP is not willing to even discuss this issue. So all my code will contain the following to eliminate this PHP bug:
// FIX PHP's bogus warning of: PHP Warning: Declaration of * should be compatible with
if (PHP_MAJOR_VERSION >= 7) {
set_error_handler(function ($errno, $errstr) {
return strpos($errstr, 'Declaration of') === 0;
}, E_WARNING);
}