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 6828327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:22:12+00:00 2026-05-26T22:22:12+00:00

What is implementing a function? normally, what I know is implementing an interface which

  • 0

What is implementing a function? normally, what I know is implementing an interface which has

function foo(); 

and implementing like

function foo($bar)

in another class

but what happens when I implement the function in the interface? do I have to reimplement them in the subclasses? or can I use them in subclasses directly, assuming they are implemented in the subclasses.

interface ibarbar{
function foo($bar)
{ 
 return $bar.$bar;}
}

class barbar implements ibarbar
{
 function baz()
 {
 $this->barbar(); //used without implementing in subclass. expected results unknown.
 }
}

PHP documentation says

// This will not work
// Fatal error: Class BadTemplate contains 1 abstract methods
// and must therefore be declared abstract (iTemplate::getHtml)
class BadTemplate implements iTemplate
{
    private $vars = array();

    public function setVariable($name, $var)
    {
        $this->vars[$name] = $var;
    }
}

so all methods in an interface are abstract methods. but I couldn’t find how to extend a function. or implement a function

  • 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-05-26T22:22:13+00:00Added an answer on May 26, 2026 at 10:22 pm

    You can’t implement a function in an interface. You can only specify its signature.


    If you want to specify signatures for some methods but provide implementation for others, use an abstract class:

    abstract class A {
        abstract public function B($c);
    
        public function C($d) {
            // do something
        }
    }
    class B extends A {
        public function B($c) { // need to implement B, as it is abstract
            $this->C($c);       // but can directly use C, as it is not
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried implementing a function like this, but unfortunately it doesn't work: const wchar_t
I am implementing a backtrace function in C, which can output caller's info. like
I'm implementing a function that receives an argument which it needs to convert to
I am implementing a function to recursively reverse a linked-list, but getting seg-fault. typedef
Does anyone know a good solution for implementing a function similar to Ruby's timeout
I am implementing a logging function and I would like to keep track of
When implementing download function it work but during file saving to sdcard i get
If I have: class foo implements Cloneable and then do: bar = new foo();
I am working on implementing a function that would execute another function a few
I have a JSFiddle that seems like it should work but it doesn't. function

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.