Quick question about the ArraySerializable hydrator


#1

Hi,

a quick question about Zend\Hydrator\ArraySerializable. What is the reason for passing the same object to a method of the object?

I don’t get it.

Thanks,

Ralf


#2

If you don’t do that, and the object only keeps the hydrated properties, then the pre-existing non-colliding fields will be gone.

You can test it with a class like this one:

class Foo {

public $properties = [‘bar’ => ‘baz’];

public function getArrayCopy():array{return $this->properties;}

public function exchangeArray(array $a):void{$this->properties=$a;}

}

Another way to verify this is to drop the code you do not understand and run the tests.


#3

Sorry, but I still don’t get it. The unit test does not even test that if I understand it correctly. It still does not make any sense to me.


#4

This is correct, but I think Ralf means not the entire code block only this one line:

$original = $object->getArrayCopy($object);

If we compare the interface from zend-stdlib:

and the ArrayObject:

http://php.net/manual/en/arrayobject.getarraycopy.php

then we will not find any parameters.


#5

If it is not tested, that’s an issue for the repo IMO: it should be tested to prevent regressions.


#6

Yes, my issue is exactly about that line that @froschdesign pointed out. It just makes no sense to me why I should pass the instance of an object to a method of that object. And both the interface and the ArrayObject don’t take such an parameter.


#7

Most likely a mistake to be corrected then: test, BC break notes, fix, and we can schedule it for the next major release :+1: