private static function mergeIntoProperty(&$object, $property, $value, $alwaysArray = false, $unique = false)
    {
        // No need to add a null value
        if (null === $value) {
            return;
        }

        if (is_array($value)) {
            // Make sure empty arrays are created since we preserve them in expansion
            if ((0 === count($value)) && (false === property_exists($object, $property))) {
                $object->{$property} = array();
            }

            foreach ($value as $val) {
                static::mergeIntoProperty($object, $property, $val, $alwaysArray, $unique);
            }

            return;
        }

        if (property_exists($object, $property)) {
            if (false === is_array($object->{$property})) {
                $object->{$property} = array($object->{$property});
            }

            if ($unique) {
                foreach ($object->{$property} as $item) {
                    if (self::subtreeEquals($item, $value)) {
                        return;
                    }
                }
            }

            $object->{$property}[] = $value;
        } else {
            $object->{$property} = ($alwaysArray) ? array($value) : $value;
        }
    }
private static function mergeIntoProperty(&$object, $property, $value, $alwaysArray = false, $unique = false)
    {
        // No need to add a null value
        if (null === $value) {
            return;
        }

        if (is_array($value)) {
            // Make sure empty arrays are created since we preserve them in expansion
            if ((0 === count($value)) && (false === property_exists($object, $property))) {
                $object->{$property} = array();
            }

            foreach ($value as $val) {
                static::mergeIntoProperty($object, $property, $val, $alwaysArray, $unique);
            }

            return;
        }

        if (property_exists($object, $property)) {
            if (false === is_array($object->{$property})) {
                $object->{$property} = array($object->{$property});
            }

            if ($unique) {
                foreach ($object->{$property} as $item) {
                    if (self::subtreeEquals($item, $value)) {
                        return;
                    }
                }
            }

            $object->{$property}[] = $value;
        } else {
            $object->{$property} = ($alwaysArray) ? array($value) : $value;
        }
    }
private static function mergeIntoProperty ( & $ object , $ property , $ value , $ alwaysArray = false , $ unique = false ) { // No need to add a null value if ( null === $ value ) { return ; } if ( is_array ( $ value ) ) { // Make sure empty arrays are created since we preserve them in expansion if ( ( 0 === count ( $ value ) ) && ( false === property_exists ( $ object , $ property ) ) ) { $ object -> { $ property } = array ( ) ; } foreach ( $ value as $ val ) { static :: mergeIntoProperty ( $ object , $ property , $ val , $ alwaysArray , $ unique ) ; } return ; } if ( property_exists ( $ object , $ property ) ) { if ( false === is_array ( $ object -> { $ property } ) ) { $ object -> { $ property } = array ( $ object -> { $ property } ) ; } if ( $ unique ) { foreach ( $ object -> { $ property } as $ item ) { if ( self :: subtreeEquals ( $ item , $ value ) ) { return ; } } } $ object -> { $ property } [ ] = $ value ; } else { $ object -> { $ property } = ( $ alwaysArray ) ? array ( $ value ) : $ value ; } }
Merges a value into a property of an object

@param JsonObject $object      The object.
@param string     $property    The name of the property to which the value
should be merged into.
@param mixed      $value       The value to merge into the property.
@param bool       $alwaysArray If set to true, the resulting property will
always be an array.
@param bool       $unique      If set to true, the value is only added if
it doesn't exist yet.
Merges a value into a property of an object