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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:18:14+00:00 2026-06-13T05:18:14+00:00

From the code below, does anyone know of a way to put the value

  • 0

From the code below, does anyone know of a way to put the value of $parent->foo and $parent->foo1 into $child->bar and $child->bar1, respectively, from a method defined in B?

I can copy the values with $child->bar=$parent->foo and $child->bar1=$parent->foo1 outside the objects but it feels like there could be a simple method in the child (or even the parent for that matter) for this situation. My parent object is getting the values of the foo’s from html input boxes.

Class A 
{
    public $foo="someText";
    public $foo1="someOtherText";
}

Class B extends A 
{
    public $bar;
    public $bar1;

    //theoretical function Id like to use
    public copyParentcontents() 
    {

    }
}

$parent = new A();
$child = new B();
  • 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-13T05:18:15+00:00Added an answer on June 13, 2026 at 5:18 am
    Class B extends A {
    
    public $bar;
    public $bar1;
    
    //theoretical function Id like to use
    public copyParentcontents($parent) {
        if(get_class($parent)=="A"){
            $this->$bar = $parent->foo;
            $this->$bar1 = $parent->foo1;
        }else{
        //You could throw an exception here
        }
    }
    
    }
    

    and then:

    $parent= new A; $child= new B; 
    $parent->foo = "modifiedText";
    $child->copyParentcontents($parent);
    

    Perhaps this is what you need?

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

Sidebar

Related Questions

Does anyone know of a fast way in VB to go from a string
Does anyone know a way to get list of jQuery themes from http://jquery-ui.googlecode.com/svn/tags/1.8.23/themes/ ?
From the code below I am getting a cell value from the selected row
I am getting a Value cannot be null error from the code below: @Html.Label(material.ExtendedGroup)
I have 2 files in the directory bar for testing. from the code below,
Does anyone here know of any quick, clean way to convert csv files to
Does anyone know a clean way to get near-LIFO or even not near-FIFO (e.g.
Does anyone know why the behaviour of throwing exceptions within a PUT action method
Does anyone know how to run the tests from a different gradle project and
I have some really funky code. As you can see from the code below

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.