Solve PHP Warning:  Creating default object from empty value in … \plugins\scribe\scribe.php on line 620

Solve PHP Warning: Creating default object from empty value in … \plugins\scribe\scribe.php on line 620

After installing the excellent Scribe plugin recently on a WordPress 4.2.2 website, I clicked to edit a page and was greeted with the following message instead of the usual page layout:

PHP Warning:  Creating default object from empty value in F:\PLESK\WWW\security.freshmango.com\httpdocs\wp-content\plugins\scribe\scribe.php on line 620

A bit of research indicated that this error is caused by manipulation of empty or unassigned variables.  I looked at the Scribe plugin source code and found line 620 which turned out to be the emboldened line below (show in its function for context):

 public static function display_analysis_meta_box($post) {
 $content_analysis = self::get_content_analysis($post->ID);
 $remaining_evaluations = self::get_content_analysis_evaluations_remaining(self::get_account());

 $content_analysis->keywordList = self::get_content_analysis_keywords( $content_analysis );

 include( SCRIBE_PLUGIN_DIR . 'views/backend/meta-boxes/content-analysis.php' );
 }

It appears that at this stage the variable $content_analysis is being used but isn’t defined/set (I can’t say for sure as when it comes to PHP I’m no expert!).

I solved the problem by simply editing the code within WordPress and adding a qualifying IF condition using the  ‘isset’ function:

 public static function display_analysis_meta_box($post) {
  $content_analysis = self::get_content_analysis($post->ID);
 $remaining_evaluations = self::get_content_analysis_evaluations_remaining(self::get_account());
 if (!isset($content_analysis)) {
 $content_analysis->keywordList = self::get_content_analysis_keywords( $content_analysis );
 }
 include( SCRIBE_PLUGIN_DIR . 'views/backend/meta-boxes/content-analysis.php' );
 }

Hopefully this will help others!  For anyone looking for a good guide on WordPress plugin coding and/or development, I highly recommend ‘Professional WordPress Plugin Development‘.

Bob McKay

About Bob McKay

Bob McKay works at Perfect Image, is a father, programmer and a self confessed techie-geek type.

Disclosure Policy

Bob on Google+

Leave a Reply

Your email address will not be published. Required fields are marked *