php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74488 Just flat wrong: "Warning: Declaration of * should be compatible with"
Submitted: 2017-04-22 11:52 UTC Modified: 2017-04-22 12:35 UTC
From: appacc2040 at gmail dot com Assigned:
Status: Not a bug Package: Compile Warning
PHP Version: 7.1.4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: appacc2040 at gmail dot com
New email:
PHP Version: OS:

Further comment on this bug is unnecessary.

 

 [2017-04-22 11:52 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-22 11:58 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2017-04-22 12:15 UTC] 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 12:23 UTC] spam2 at rhsoft dot net
At least give us "somekeyword_stating_dontmatter class extends parent_class"
 [2017-04-22 12:34 UTC] nikic@php.net
-Block user comment: No +Block user comment: Yes
 [2017-04-22 12:35 UTC] nikic@php.net
If you wish to suggest a syntax extension, please submit a proposal to the internals mailing list. There will be no need for further comments on this issue.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC