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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:49:53+00:00 2026-05-25T12:49:53+00:00

I have a feeling that what I am trying to do is impossible as

  • 0

I have a feeling that what I am trying to do is impossible as I can’t find anything on it. I have a few classes that extend from another class. Inside of the class that is being extended, I have to call some unique code based on which class is calling it.

This is something of an in-depth project, so I created a testcase that should explain what I am trying to do:

class parent {
    function traverseTable($table) {
        foreach($table->getElementsByTagName('tr') {
            $rowCnt++;
            $this->uniqueSearch($rowCnt);
        }
    }
}

class child1 extends parent {
    function search($input) {
        //parse input, get $table
        $this->traverseTable($table);
    }

    function uniqueSearch($rowCnt) {
         echo 'child1';
        //Do different things
    }
}

class child2 extends parent {
    function search($input) {
        //parse input, get $table
        $this->traverseTable($table);
    }

    function uniqueSearch($rowCnt) {
         echo 'child2';
        //Do different things
    }
}

Basically, I want to be able to call the uniqueSearch() function from inside the loop in Class Parent; but the above syntax does not seem to work. Anybody have any ideas? The real size of the uniqueSearch functions vary from 20-100 lines at this point, but might get bigger.

  • 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-25T12:49:53+00:00Added an answer on May 25, 2026 at 12:49 pm

    So, you want to call uniqueSearch polymorphically.

    1. Your first problem has nothing to do with this, and is that parent is a reserved word:

      Fatal error: Cannot use ‘parent’ as class name as it is reserved on line 2

      Fix that.

    2. Your next problem is a simple syntax error:

      Parse error: syntax error, unexpected ‘{‘ on line 4

      Fix that.

    3. Then, you have the issue that there is no $table, and no getElementsByTagName in your testcase. Also foreach ($table->getElementsByTagName('tr')) is not valid PHP.

      Fix that.

    4. Your testcase doesn’t call any functions.

      Fix that.

    Result:

    <?php
    class base {
        function traverseTable($table) {
            foreach ($table as $element) {
                $rowCnt++;
                $this->uniqueSearch($rowCnt);
            }
        }
    }
    
    class child1 extends base {
        function search($input) {
            //parse input, get $table
            // dummy for now:
            $table = Array(0,1,2,3);
            $this->traverseTable($table);
        }
    
        function uniqueSearch($rowCnt) {
             echo 'child1';
            //Do different things
        }
    }
    
    class child2 extends base {
        function search($input) {
            //parse input, get $table
            // dummy for now:
            $table = Array(0,1,2,3);
            $this->traverseTable($table);
        }
    
        function uniqueSearch($rowCnt) {
             echo 'child2';
            //Do different things
        }
    }
    
    $c1 = new child1;
    $c2 = new child2;
    
    $c1->search("");
    $c2->search("");
    ?>
    

    And now it works just fine:

    child1child1child1child1child2child2child2child2

    This question had nothing to do with polymorphism whatsoever, as it turns out; just silly syntax errors.

    Thanks for playing.

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

Sidebar

Related Questions

I have the feeling that is easy to find samples, tutorials and simple examples
I have a feeling this is a repost but I can't seem to find
I have a feeling that I'm in over my head. I'm trying to write
I have a feeling that I already know the answer to this one, but
I have a feeling that there must be client-server synchronization patterns out there. But
I have the feeling that Flash -based ( or Silverlight -based) websites are generally
I have a feeling that this query is pretty easy to construct, I just
I somehow have the feeling that modern systems, including runtime libraries, this exception handler
This is an SDL problem, however I have the strong feeling that the problem
I have a feeling this XML is not valid, can someone please explain why?

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.