Il 23/07/21 12:36, Arno Welzel ha scritto:
> alex:
>
>> Why?
>>
>> Here is the demonstration:
>>
>> array_merge(
>> new ArrayObject,
>> new ArrayObject,
>> );
>>
>>
>> Warning: array_merge(): Expected parameter 1 to be an array, object given
>
> Yes - this is the expected result. That's why there is getArrayCopy():
>
> <
https://www.php.net/manual/en/arrayobject.getarraycopy.php>
>
>
class MyClass {
function __toString(){
return __CLASS__;
}
}
function my_function(string $string){
echo "$string\n";
}
echo "Object to string implicit conversion: OK \n";
my_function(
new MyClass
);
echo "Object to array implicit conversion: ERROR \n";
array_merge(
new ArrayObject,
new ArrayObject,
);
Output:
Object to string implicit conversion: OK
MyClass
Object to array implicit conversion: ERROR
Warning: array_merge(): Expected parameter 1 to be an array, object
given in /home/rino/Scaricati/esperimenti/merge-ArrayObject.php
Why?