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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:08:26+00:00 2026-06-13T11:08:26+00:00

Lets see a basic class: class A { public function renderSomethingRecursive() { //this function

  • 0

Lets see a basic class:

class A
{
   public function renderSomethingRecursive()
   {
      //this function can call itself
      self::renderSomethingRecursive(); // ERROR!!!!
   }

   abstract public function addSomething (value);
}

class B extends A
{
   public function renderSomethingRecursive()
   {
      throw new Exception ('This time this method must not be called!');
   }

   public function addSomething (value)
   {
      //something, something, something....
      parent::renderSomethingRecursive();
   }
}

$obj = new B();
$obj->addSomething(....);

when I do this, B::renderSomethingRecursive() still gets called, which I dont want… on A:renderSomethingRecursive() method, at self::renderSomethingRecursive(); // ERROR!!!! line calls B::renderSomethingRecursive(); instead of A::renderSomethingRecursive();, which is reasonable since $this is now B and not A… but then I have no idea how to dodge it.

Btw, I know B::renderSomethingRecursive() method should just be removed, but I wanted to keep it as a notice that it mustnt be called by accident. I wanted to make it “private” to make this unavailable, but as we know, its not possible 🙂

Any ideas?

  • 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-13T11:08:27+00:00Added an answer on June 13, 2026 at 11:08 am

    Why have you defined the method in B if you don’t want it to be called. Just don’t define it, and there’s only 1 method PHP can call. That way, you don’t have to use parent::theMethod, you can easily just call it using this->theMethod();

    Abstract class A
    {
       public function renderSomethingRecursive()
       {
          $this->renderSomethingRecursive(); // no need for self::, that's for static calls
       }
    
       abstract public function addSomething (value);
    }
    
    class B extends A
    {
       public function addSomething (value)
       {
          $this->renderSomethingRecursive();//calls the abstract method as though it were defined in class B
       }
    }
    

    that’s all, really

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I screwed up my last post. Lets see if I can get this one
Let's see if I can make the step-by-step clear: namespace InventoryManager.Controllers { public class
I have a basic class for detecting collisions but I can't figure out how
i have a basic question. lets say we have 3 classes: Class S, class
I have a web-app (let's call it app1),in which I can't even see the
A fairly basic question, but I don't see it asked anywhere. Let's say we
Let's see I want to do this, i want to get the parent of
Lets Say i have a table like this WEB_LIST_TABLE KEY Value ---------------------------------------- 134 google.com
I know I can answer this question easily for myself by generatin the code
I have a series of buttons. Lets call them A, B, C. I attached

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.