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

  • Home
  • SEARCH
  • 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 9251643
In Process

The Archive Base Latest Questions

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

I am trying to create an array of objects for which I will be

  • 0

I am trying to create an array of objects for which I will be using chaining and I am having an issue I am hoping I can get help with. Here is the code I have:

$sql = new sql();
$sqlList[] = $sql->setTable('TableTest1');
$sqlList[] = $sql->setTable('TableTest2');
$sqlList[] = $sql->setTable('TableTest3');
$testDB->delete($sqlList);

The sql class contains a private variable called table which has setter and getter methods like this:

public function setTable($setTable)
{
    $this->table = $setTable;
    return $this;
}

public function getTable()
{
    return $this->table;
}

To test this I have a simple delete method in the $testDB object like this:

public function delete($sql ,$setClear = true)
{
    echo "<pre>";
    print_r($sql);
    echo "</pre>";
}

I am hoping to return an array with elements containing the three different TableTest values but instead all three contain just the last entry of ‘TableTest3’ like this:

Array
(
[0] => sql Object
    (
        [table:sql:private] => TableTest3
    )

[1] => sql Object
    (
        [table:sql:private] => TableTest3
    )

[2] => sql Object
    (
        [table:sql:private] => TableTest3
    )
)

I am using PHP 5.4.7.
What am I doing wrong? A programmer with much more experience than me suggested this method to be able to make an array of different settings to step through and I am trying this to test my code. It appears to me it is putting a reference to the object $sql in each of the entries of the array instead of a copy of the actual object as I intend.

  • 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-18T10:45:15+00:00Added an answer on June 18, 2026 at 10:45 am

    With your setTable method looks like this:

    public function setTable($setTable)
    {
        $this->table = $setTable;
        return $this;
    }
    
    $sqlList[] = $sql->setTable('TableTest1');
    $sqlList[] = $sql->setTable('TableTest2');
    $sqlList[] = $sql->setTable('TableTest3');
    

    All three “elements” in $sqlList are only $sql.

    If you want to create a new instance upon setTable, you could try something like this:

    public function setTable($setTable)
    {
        $class=__CLASS__;
        $obj=new $class;
        $obj->table=$setTable;
        return $obj;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an array of product SKU's which I can then
I am trying to create an array of objects in Java and am having
I am trying to create an array of class objects taking an integer argument.
I'm trying to create a 2 dimensional array of Node objects as follows public
I'm trying to create an array from selected table rows so I can push
I'm trying to create an array of strings that can be randomized and limited
I am trying to create an array of numbers that I will use later
I'm trying to create an iOS application which upon loading, will initially connect via
I'm trying to write a Linq query which returns an array of objects, with
What i'm trying to do is create a template array class that will store

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.