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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:08:21+00:00 2026-05-25T17:08:21+00:00

I have an abstract class and child’s: abstract class Cubique_Helper_Abstract { abstract public function

  • 0

I have an abstract class and child’s:

abstract class Cubique_Helper_Abstract {
    abstract public function execute();
}

class Cubique_Helper_Doctype extends Cubique_Helper_Abstract{
    public function execute($type) {}
}

As you can see, method execute() is common. But number of arguments can be different in all classes. How can I keep this extending with different arguments of method?

It’s my current error:

Declaration of Cubique_Helper_Doctype::execute() must be compatible
with that of Cubique_Helper_Abstract::execute()

Thank you i advance.

  • 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-25T17:08:21+00:00Added an answer on May 25, 2026 at 5:08 pm
    • You could remove execute() from the abstract, but you probably do not want to do that.

    • You could also give it an data object as argument, like this:

      class MyOptions {
        public function getType(){}
        public function getStuff(){}
      }
      
      abstract class Cubique_Helper_Abstract {
          abstract public function execute(MyOptions $options);
      }
      
      class Cubique_Helper_Doctype extends Cubique_Helper_Abstract{
        public function execute(MyOptions $options) {
          $type = $options->getType();
        }
      }
      
    • Or, you could make it depend on values in constructor and leave out the argument:

      abstract class Cubique_Helper_Abstract {
          abstract public function execute();
      }
      
      class Cubique_Helper_Doctype extends Cubique_Helper_Abstract{
        public function __construct($type) {
          // since __construct() is not in abstract, it can be different
          // from every child class, which let's you handle dependencies
          $this->type = $type;
        }
        public function execute() {
          // you have $this->type here
        }
      }
      

    The last alternative is my favorite. This way, you really make sure you have the dependencies and when it’s time to execute() you don’t have to give it any arguments.


    I would not use func_get_args() since you lose track of dependencies. Example:

    class Cubique_Helper_Doctype extends Cubique_Helper_Abstract {
      public function execute() {
        $args = func_get_args();
        $type = $args[0];
        $title = $args[1];
        $content = $args[2];
        // do something, for example
        echo $type; // will always echo "" if you miss arguments, but you really want a fatal error
      }
    }
    
    $d = new Cubique_Helper_Doctype();
    $d->execute();
    // this is a valid call in php, but it ruins your application.
    // you **want** it to fail so that you know what's wrong (missing dependencies)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Within my code a have the following abstract superclass public abstract class AbstractClass<Type extends
I have an abstract class: type TInterfaceMethod = class abstract public destructor Destroy; virtual;
So, I have an abstract class like: public abstract class AbstractParent <E extends Enum<E>>
I have an abstract superclass. abstract class SuperClass{ public static function loadInstanceFromText(){ $instance =
I have an abstract method in a base class declared like so... public abstract
I have one abstract class and many child classes. In child classes are from
I have the following Model pattern: public abstract class PARENTCLASS {...} public class CHILD_A_CLASS
In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
Suppose we have abstract class A (all examples in C#) public abstract class A
I have an abstract base class with a TcpClient field: public abstract class ControllerBase

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.