2

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!

0

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

4 Comments

Oddly though it is defined as an array. Seems like a mismatch.
Thanks for your quick response. Fatal error: Cannot use object of type stdClass as array in helper.php. This is the error I am getting while inserting $images = new stdClass();
+1 Jeffrey do you want to send a pull request to fix that? github.com/joomla/joomla-cms
mod_random_image (it's a core module) github.com/joomla/joomla-cms/blob/master/modules/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.