Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #18737

Re: ArrayObject class unusable as array

From alex <1j9448a02@lnx159sneakemail.com.invalid>
Newsgroups comp.lang.php
Subject Re: ArrayObject class unusable as array
Date 2021-07-24 09:34 +0200
Organization Aioe.org NNTP Server
Message-ID <sdgfq4$nd3$1@gioia.aioe.org> (permalink)
References <sddtvf$11ug$1@gioia.aioe.org> <ilvkcuFls6iU1@mid.individual.net>

Show all headers | View raw


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?

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

ArrayObject class unusable as array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-07-23 10:17 +0200
  Re: ArrayObject class unusable as array Arno Welzel <usenet@arnowelzel.de> - 2021-07-23 12:36 +0200
    Re: ArrayObject class unusable as array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-07-24 09:34 +0200
      Re: ArrayObject class unusable as array Arno Welzel <usenet@arnowelzel.de> - 2021-07-25 19:03 +0200
        Re: ArrayObject class unusable as array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-07-26 09:40 +0200
          Re: ArrayObject class unusable as array Arno Welzel <usenet@arnowelzel.de> - 2021-07-26 12:12 +0200
            Re: ArrayObject class unusable as array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-07-26 12:48 +0200
              Re: ArrayObject class unusable as array Jerry Stuckle <jstucklex@attglobal.net> - 2021-07-26 14:38 -0400
              Re: ArrayObject class unusable as array Arno Welzel <usenet@arnowelzel.de> - 2021-07-30 12:34 +0200

csiph-web