简体   繁体   English

如何在“从空值创建默认对象”错误中定义值

[英]How to define a value on “Creating default object from empty value” error

I knew many question about this, I try to read but still got this error message on my Wordpress : 我对此有很多疑问,我尝试阅读但仍在我的Wordpress上收到此错误消息:

"Creating default object from empty value in /home/forthemde/public_html/wp-content/themes/mayadeep/admin/admin.php on line 225" “从第225行的/home/forthemde/public_html/wp-content/themes/mayadeep/admin/admin.php中的空值创建默认对象”

Here the code on admin.php and: 这里是admin.php上的代码和:

 function upfw_setup_theme_options(){
     $up_options_db = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
     global $up_options;
     //Check if options are stored properly
     if( isset($up_options_db) && is_array($up_options_db) ):
         //Check array to an object
         foreach ($up_options_db as $k => $v) {
                 $up_options -> {$k} = $v;
         }
     else:
         do_action('upfw_theme_activation');
     endif;
 }
 add_action('upfw_theme_init','upfw_setup_theme_options',10);
 add_action('upfw_admin_init','upfw_setup_theme_options',100);

Line 225 is here: 225行在这里:

 $up_options -> {$k} = $v;

I try to fix by myself, but no result. 我尝试自己修复,但没有结果。 Please help me, really appreciate for any help. 请帮助我,非常感谢您的帮助。

Regards. 问候。

This error is because the global object global $up_options is not defined. 该错误是因为global $up_options全局对象global $up_options

Try to var_dump $up_options , it might be null. 尝试var_dump $up_options ,它可能为null。

Also check if you have spelled the variable name correctly. 还要检查您是否正确拼写了变量名。

Run this code, and check the output: 运行以下代码,并检查输出:

function upfw_setup_theme_options(){
     $up_options_db = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
     global $up_options;

 $up_options = new stdClass();

     //Check if options are stored properly
     if( isset($up_options_db) && is_array($up_options_db) ):
         //Check array to an object
         foreach ($up_options_db as $k => $v) {
                 $up_options -> {$k} = $v;
         }
     else:
         do_action('upfw_theme_activation');
     endif;
 }
 add_action('upfw_theme_init','upfw_setup_theme_options');
 add_action('upfw_admin_init','upfw_setup_theme_options');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM