<?php
class X{
public $real = [];
public function __construct(){
$this->real ['qty']= 15;
}
public function &setData(){
return $this->real;
}
}
$x = new X();
$x->setData()['qty'] = 22;
$x->setData()['qty2'] = 'haha yeah, we should not use refs :)';
var_dump($x->real);
array(2) {
["qty"]=>
int(22)
["qty2"]=>
string(36) "haha yeah, we should not use refs :)"
}
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array(2) {
["qty"]=>
int(22)
["qty2"]=>
string(36) "haha yeah, we should not use refs :)"
}