Codeigniter-Google-Analytics-library icon indicating copy to clipboard operation
Codeigniter-Google-Analytics-library copied to clipboard

Creating default object from empty value

Open pierre-r opened this issue 11 years ago • 1 comments

Salut,

Tout d'abord, super lib !

Par contre, maintenant, avec PHP 5.4 on a un warning assez facile à corriger, il s'agit du titre de cette issue.

Severity: Warning Message: Creating default object from empty value Filename: libraries/ga_api.php Line Number: 553

Pour corriger ça, il suffit d'initialiser l'objet avec stdClass() :

Chercher

function _array_to_object($array) 
    {
        foreach ($array as $key => $value) 
        {
            $object->$key = is_array($value) ? $this->_array_to_object($value) : $value;
        }
        return  $object;
    }

Remplacer par

function _array_to_object($array) 
    {
        $object = new stdClass();
        foreach ($array as $key => $value) 
        {
            $object->$key = is_array($value) ? $this->_array_to_object($value) : $value;
        }
        return  $object;
    }

Tant que j'y suis, une petite amélioration pour le dossier cache : s'il n'existe pas, il ne sera jamais créé et donc le cache jamais utilisé... c'est pas vraiment cool :/ Pour corriger ça, chercher :

function _store_data()
    {
        if (file_exists($this->cache_folder) && is_dir($this->cache_folder))
        {   
            if ($this->cache_data) 
            {
                $file = fopen($this->cache_folder.md5($this->query_string).'.'.$this->cache_ext, 'w');
                fwrite($file, $this->data_file);
            }
            return true;
        }
        return false;
    }

Remplacer par

function _store_data()
    {
        if (file_exists($this->cache_folder) && is_dir($this->cache_folder))
        {   
            if ($this->cache_data) 
            {
                $file = fopen($this->cache_folder.md5($this->query_string).'.'.$this->cache_ext, 'w');
                fwrite($file, $this->data_file);
            }
            return true;
        } else {
            mkdir($this->cache_folder, 0755, TRUE);
        }
        return false;
    }

pierre-r avatar Jul 03 '13 08:07 pierre-r

C'est une erreur de type E_STRICT, qui est désormais incluse dans le E_ALL de php 5.4. Je te propose de faire une Pull Request et l'intègrerais au dépôt.

Pour le cache, il faudrait aussi vérifier si il est possible d'écrire dans le dossier, avec un is_writable() par exemple.

ronan-gloo avatar Jul 03 '13 08:07 ronan-gloo