Codeigniter-Google-Analytics-library
Codeigniter-Google-Analytics-library copied to clipboard
Creating default object from empty value
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;
}
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.