NewPHP
NewPHP

Reputation: 608

Warning: Creating default object from empty value in joomla while upgrading PHP

I have searched a lot for this issue. But couldn't find the exact answer. I am getting this error Warning: Creating default object from empty value in mod_random_image/helper.php on line 85. My code is given below:

 58         function getImages(&$params, $folder)
 59         {
 60                 $type           = $params->get( 'type', 'jpg' );
 61 
 62                 $files  = array();
 63                 $images = array();
 64 
 65                 $dir = JPATH_BASE.DS.$folder;
 66 
 67                 // check if directory exists
 68                 if (is_dir($dir))
 69                 {
 70                         if ($handle = opendir($dir)) {
 71                                 while (false !== ($file = readdir($handle))) {
 72                                         if ($file != '.' && $file != '..' && $file != 'CVS' && $file != 'index.html' ) {
 73                                                 $files[] = $file;
 74                                         }
 75                                 }
 76                         }
 77                         closedir($handle);
 78 
 79                         $i = 0;
 80                         foreach ($files as $img)
 81                         {
 82                                 if (!is_dir($dir .DS. $img))
 83                                 {
 84                                         if (preg_match("#$type#i", $img)) {
 85                                                 $images[$i]->name       = $img;
 86                                                 $images[$i]->folder     = $folder;
 87                                                 ++$i;
 88                                         }
 89                                 }
 90                         }
 91                 }
 92 
 93                 return $images;
 94         }

This error is getting after I upgraded PHP version to 5.4.8. I have looked into the joomla configuration file also. I set the var $error_reporting = '-1'; in the joomla configuration. But I am still getting the same error. I haven't used Joomla before.

Any help will be appreciated. Thanks!

Upvotes: 2

Views: 7997

Answers (1)

Shoe
Shoe

Reputation: 76260

The error occurs because $images[$i] has not been defined yet as an object and PHP instantiated a default object (of type stdClass) implicitely. To solve this problem just add this line before line 85:

$images[$i] = new stdClass();

Upvotes: 2

Related Questions