public static function set(array &$array, $keyPath, $value)
    {
        self::checkKeyPathIsValidAndNonEmpty($keyPath);
        $keys = self::explodeKeys(strval($keyPath));
        $result = $array;
        $ptr = &$result;

        $parentKeys = array();
        while ($keys !== array()) {
            $key = array_shift($keys);
            $parentKeys[] = $key;

            if (!array_key_exists($key, $ptr)) {
                $ptr[$key] = $keys === array() ? $value : array();
                $ptr = &$ptr[$key];
                continue;
            }
            $ptr = &$ptr[$key];
            if ($keys === array()) {
                $ptr = $value;
                break;
            }
            elseif (!is_array($ptr)) {
                throw new InconsistentKeyTypes($ptr, array(), implode('.', $parentKeys));
            }
        }

        $array = $result;
    }