php-collection icon indicating copy to clipboard operation
php-collection copied to clipboard

Warning: Illegal offset type in isset or empty in \vendor\phpcollection\phpcollection\src\PhpCollection\AbstractMap.php line 134

Open JarJak opened this issue 10 years ago • 6 comments

Warning: Illegal offset type in isset or empty in \vendor\phpcollection\phpcollection\src\PhpCollection\AbstractMap.php line 134

when trying do deserialize a prieviously serialized object with jms-serializer:

$json = $this->serializer->serialize($object, 'json', SerializationContext::create()->enableMaxDepthChecks());
$this->serializer->deserialize($json, 'json', SerializationContext::create()->enableMaxDepthChecks());

JarJak avatar Jan 16 '15 11:01 JarJak

hello?

JarJak avatar Feb 10 '15 09:02 JarJak

@JarJak I'm guessing jms-serializer is out of scope for this package. If you need this fixed, then you are going to have to dig into it yourself and report back with more details.

judgej avatar Jul 02 '15 10:07 judgej

For future reference, your function arguments are not ok for deserialize: You need the jsonText, objectClassName, 'json' or 'xml' (type), DeserializationContext

doofer avatar Jan 12 '17 19:01 doofer

@doofer you are probably right. Anyway it would be nice to check key type before using isset(). Like:

    public function containsKey($key)
    {
        if (is_array($key) || is_object($key)) {
            //throw...
        }
        return isset($this->elements[$key]);
    }

JarJak avatar Sep 11 '18 18:09 JarJak

@JarJak Which could be wrong for the object case in some cases, as we can provide a __toString().

discordier avatar Sep 12 '18 22:09 discordier

@discordier so:

    public function containsKey($key): bool
    {
        if (is_array($key) || (is_object($key) && !method_exists($key, '__toString')) ) {
            //throw...
        }
        return isset($this->elements[$key]);
    }

JarJak avatar May 28 '21 14:05 JarJak