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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:59:38+00:00 2026-05-27T22:59:38+00:00

I want to add additional stuff to the parent class. I can’t modify the

  • 0

I want to add additional stuff to the parent class.
I can’t modify the parent class because all modifications will be erased when the software is upgraded. So I want to extend the class. Can I just add this in the child class without repeating parent functions?

class parent
{
    public function __construct()
    {
        // lots of logic to hook up following functions with main software
    }

      // lots of parent functions
}

class child extends parent
{
     function __construct()
    {
        // Is this going to share parent's logic and hook up with those actions?
        // Or, should I repeat those logics?
        parent::__construct();

        // add child addicional logic
    }
     // child functions
    // should I repeat parent's functions? I need the parent take child along all the jobs.

}
  • 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-27T22:59:39+00:00Added an answer on May 27, 2026 at 10:59 pm

    Yes, that is the correct way to do it.

    class parent
    {
        public function __construct()
        {
            // lots of logic to hook up following functions with main software
        }
        // lots of parent functions
    
        protected function exampleParentFunction()
        {
            //do lots of cool stuff
        }
    }
    
    class child extends parent
    {
         function __construct()
        {
            // This will run the parent's constructor
            parent::__construct();
            // add child additional logic
        }
        // child functions
        public function exampleChildFunction();
        {
            $result = $this->exampleParentFunction();
            //Make result even cooler :)
        }
        //or you can override the parent methods by declaring a method with the same name
        protected function exampleParentFunction()
        {
            //use the parent function
            $result = parent::exampleParentFunction();
            //Make result even cooler :)
        }
    }
    

    Going by your recent questions you really need to read a book on PHP OOP. Start with the manual http://www.php.net/oop

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

Sidebar

Related Questions

I want to add additional criteria to the LEFT OUTER JOIN generated by the
I want to add an additional roadblock in my application to prevent automating it
I want to add an additional value into an array before passing it to
I have dbml with single table users i want add partial class for User
We have completed 95% of our application. We want to add additional argument mode=1
In Teamcity I'm kicking off an Ant Build. I want to add additional jars
I am getting all events, with a certain attribute, and I want to modify
I want to add same additional fields to my form, but I don't want
I have an array with string values. I want to add additional text before
Hi I want to add additional attribute when a user is register through ASP.NET

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.