in Education by
I currently have 2 classes: workerListClass workerClass The workerListClass gets a list of work with ids from database. For each of these the workerClass is called foreach ($query as $value) { $result = $this->worker->getWorkerById($value['ID']); // DB Call to get additional data $this->addData($result); vardumper::dump($result->getId()); // This results in 1031 and 1528 } addDate is very simple public function addData(workerClass $worker): void { $this->data[] = $worker; } But if i try to go through this array something strange happens $result = $this->workerListClass->getWorker()->getData(); foreach ($result as $worker) { vardumper::dump([ $worker->getId() // this outputs 1528 twice!!! ]); } getData does nothing special public function getData(): array { return $this->data; } Can someone help me why this outputs 1528 twice? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Problem found. The issues was that the same class was changed and not a new class was setup. Using clone on the workerlist helped fixing this: foreach ($query as $value) { $localWorker = clone $this->worker; //starts a new instance so that it is not referenced $result = $localWorker->getWorkerById($value['ID']); $this->addData($result); vardumper::dump($result->getId()); }

Related questions

0 votes
    So like when working with mysql_fetch_object(), how do you do things like this: $array = array(); ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    What happens if you add your just created object to a mutable array, and you release your object?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    I have an Item entity which have an "access" field, typed as json, that is added through a migration. I'm ... syntax. Currently I'm trying to do something like $this->addSql(...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I writing a function in my form that require user to upload a file, but doesn't necessary have to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    How to solve array problem? $kuponlar = $core->query("SELECT * FROM kupon WHERE kupon_durum = ?", ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    How to solve array problem? $kuponlar = $core->query("SELECT * FROM kupon WHERE kupon_durum = ?", ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    I try to print images with a for loop but the images dont load. The images are in the same ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I try to print images with a for loop but the images dont load. The images are in the same ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    I am trying to echo out an array using for each but it's not displaying any values. The only ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I am trying to echo out an array using for each but it's not displaying any values. The only ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Dec 28, 2021 in Education by JackTerrance
0 votes
    I have a dataset that only contains y-values in one column. I want to insert a column of x- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a field call query_data defined as text in my MySQL database. In my model I defined this ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    How to add an element into an Array?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    I am retrieving messages from an Outlook account. I am trying to get inline files and attachments from ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
...