I have a problem when I pass data through from one function to a class that it is updating the data that I am passing in the origination class in even though I am not doing it by reference.
<?php
namespace core\Test\Libraries;
public function hasPurchasedCorrectProducts()
{
$testData = [];
$testData['one'] = new \stdClass();
$testData['one']->qty = 2;
(new \core\Libraries\Debug())->printData($testData, false); // see below #1
(new StupidTest())->test($testData);
(new \core\Libraries\Debug())->printData($testData, false);exit; // see below #3
}
}
<?php
namespace core\Test\Libraries;
class StupidTest
{
private $availableProducts;
public function test($availableProducts)
{
$this->availableProducts = $availableProducts;
$this->availableProducts['one']->qty = ($this->availableProducts['one']->qty - 1)
;
(new \core\Libraries\Debug())->printData($this->availableProducts, false); // see below #2
}
}
1
Array
(
[one] => stdClass Object
(
[qty] => 2
)
)
2
Array
(
[one] => stdClass Object
(
[qty] => 1
)
)
3
Array
(
[one] => stdClass Object
(
[qty] => 1
)
)
How is $testData in #3 getting updated?