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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:23:50+00:00 2026-06-11T12:23:50+00:00

When I do a query in class A, I got all data already. class

  • 0

When I do a query in class A, I got all data already. class B need to use some of the data. I prefer pass part of the query result to B than do a new query in B. Class B will perform some jobs and the data will be changed in class B. How to pass the array $something_else to class B? Here is the classes:

class A{
  public $something;
  private $_project_obj;
  function __construct( $id = null ){
    if ( $id ) {
       $this->id = $id;
       $this->populate( $this->id );
    }
}
 function populate(){
      $query = //do query
      $this->somthing= $query['A'];
      $this->something_else = $query['B'];
}
 function save(){
     // call save() in class B, $something_else is saved there
     if ( $this->_project_obj instanceof B ) {
    if ( true !== $this->_project_obj->save() ) {
        return false;
    }
    }
    // save $something and other stuffs in class A
   //  ......
   }
  function project() {  
    if ( !$this->_project_obj instanceof B ) {
     if ( ( $this->id ) && ( loggedin_user_id() ) ) {
       $this->_project_obj = new B( $this->id, loggedin_user_id() );
    } else {
    return false;
    }
    }
     return $this->_project_obj
    }
}
class B{
  public $data_this;
  public $data_that;
  function __constructor( $id=null, $user_id=null){
      if($id && $user_id){
        return $this->populate();
      }
      return true;

  }
 function populate(){
  $query = // do the same query as in class A
  $something_else = $query['B'];
  $this->data_this = $something_else['a'];
  $this->data_that = $something_else['b'];
 }
 function save(){
  // save all data as $something_else 
 }
 function jobs(){
 // perform 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-06-11T12:23:52+00:00Added an answer on June 11, 2026 at 12:23 pm

    It’s not clear where in B you’re needing something_else, so let’s just add it as part of the constructor: Make the constructor function accept an additional parameter of something_else and save it to that class’ property:

    class B{
      private var $_parent;
      function __constructor( $parent, $id=null, $user_id=null){
          $this->_parent = $parent; // Save reference to the "A" that contains this "B"
          if($id && $user_id){
            return $this->populate();
          }
          return true;
    
      }
    

    When A creates a B: $this->_project_obj = new B( $this, $this->id, loggedin_user_id() );

    And when B needs to get the latest version of something_else from its parent A: $this->_parent->something_else

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

Sidebar

Related Questions

Is there a JSON query class or jQuery plugin that I can use to
I'm using CodeIgniter's Active Record class to query the MySQL database. I need to
I've got a simple POCO class to hold data extracted from an XML file
I have some things I need to use custom SQL for. Just to start,
I want to populate data in expandableListView from database. Actually all I need to
I got some data inputed by the user that should be added to a
I've got a PHP database class which connects to MySQL and wraps up all
I'm new to all this. I've got a template for a mock website I'm
This is my query: class services extends Zend_Db_Table{ function Get_Services($user_id){ $DB = Zend_Db_Table_Abstract::getDefaultAdapter(); $select
I have a Query model: class Query < ActiveRecord::Base belongs_to :test end which is

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.