Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:33:54+00:00 2026-06-15T19:33:54+00:00

Why do I receive this error: Fatal error: Declaration of ConcreteFooMapper::load() must be compatible

  • 0

Why do I receive this error:

Fatal error: Declaration of ConcreteFooMapper::load() must be compatible with that of AbstractFooMapper::load() on line 18

from this code:

<?php
interface Foo {
    public function foo();
}

class ConcreteFoo implements Foo {
    public function foo() {

    }
}

abstract class AbstractFooMapper {
    abstract public function load(Foo $entity, array $data);
}

class ConcreteFooMapper extends AbstractFooMapper {
    public function load(ConcreteFoo $entity, array $data) {

    }
}
?>

My initial thought is that it’s a bug; PHP isn’t detecting that ConcreteFoo implements Foo when it is evaluating the method declaration it. I think this because when you run this code:

<?php
interface Foo {
    public function foo();
}

class ConcreteFoo implements Foo {
    public function foo() {

    }
}

$foo = new ConcreteFoo();

if ($foo instanceof Foo) 
{
    print 'w00t!';
} 
else 
{
    print 'FAIL!';
}
?>

it prints w00t! indicating ConcreteFoo is an instance of Foo.

Any insights into whether this behavior is correct or not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:33:55+00:00Added an answer on June 15, 2026 at 7:33 pm

    The class implementing the interface must use the exact same method signatures as are defined in the interface. Not doing so will result in a fatal error. And same rules for classes which extends abstract classes.

    Please, see in see in details here, see here too

    And this is right behaviour \ logic.

    check here Abstract types are useful in that they can be used to define and enforce a protocol; a set of operations which all objects that implement the protocol must support.

    if we assume that your code will work without exception, then we have following problem: ConcreteFooMapper can’t use instances of some class ConcreteFoo2 implements Foo as parameter for load method, but should (by Abstract class definition)

    Also, if you use same signature, it not a problem really, cause all class \ type info available. Please, check following code

    <?php
    interface Foo {
            public function foo();
    }
    
    class ConcreteFoo implements Foo {
            public function foo() {
            }
    }
    
    abstract class AbstractFooMapper {
            abstract public function load(Foo $entity, array $data);
    }
    
    class ConcreteFooMapper extends AbstractFooMapper {
            public function load(Foo $entity, array $data) {
                    var_dump($entity instanceof Foo);
                    var_dump($entity instanceof ConcreteFoo);
            }
    
    }
    
    $someConcreteFoo = new ConcreteFoo();
    $someFooMapper = new ConcreteFooMapper();
    
    $someFooMapper->load($someConcreteFoo, array('somekey' => 'somevalue'));
    // output
    // bool(true) bool(true)  
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Try To Receive Data From A Web-Service Using This Code But An Fatal-Error
THE SUMMARY: When I call .../index.php/product, I receive: Fatal error: Call to a member
I'm running FreeBSD with PHP 5.4.3. I receive the error: fatal error: call to
I receive this error when I click on the section of my Tab-Bar application
I'm having a problem where I receive this error: Exception in thread main java.lang.NullPointerException
I received this error on following code.Is this + sign is not available in
I received >>> THIS <<< error log from a client. I replaced the app
I want to raise an event from a .NET class, and receive this event
In my program on this line: int value = MTEConnect(auth_string, err); I receive such
I received the following error: [27-Apr-2009 10:26:06] PHP Fatal error: Cannot redeclare alphanumeric() (previously

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.