in a situation like that below,
class my_class {
public __construct($params = array()){
**** do something
}
}
$other_object = new some_class();
$object = new my_class(array(
'var1' => 'test'
'object' => $other_object));
$other_object will be passed by reference or by value?
Longer answer: Like all Java objects, arrays are passed by value ... but the value is the reference to the array. So, when you assign something to a cell of the array in the called method, you will be assigning to the same array object that the caller sees. This is NOT pass-by-reference.
Object references are passed by value The reason is that Java object variables are simply references that point to real objects in the memory heap. Therefore, even though Java passes parameters to methods by value, if the variable points to an object reference, the real object will also be changed.
Arrays are always pass by reference in C. Any change made to the parameter containing the array will change the value of the original array.
Objects are always references, except you clone
it explicitly.
You can use spl_object_hash()
to retrieve the "object id" and then compare them against each other. Remember, that once an object is removed from the memory by the garbage collector, the ID may get reused.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With