开发者

PHP Function Parameter is always null in Wordpress

I am not an expert Wordpress PHP developer but I am not understanding this situation. I am passing a variable through a static function into the $GLOBALS variable that contains an array. That variable when in the static function is always NULL, but before it goes into it, it is a valid type and prints fine.

functions.php

$badge_Id = get_comment_meta($comment->comment_ID,"badge_id", true);

   if(strlen($badge_Id) > 0) {
        Cisco_Rewards::add_badge_id($badge_id);
                echo $badge_id; // PRINTS PERFECTLY
   }

rewards.php

class Cisco_Rewards {

static function add_badge_id($badge_id) {
        i开发者_开发问答f(count($GLOBALS['badge_ids']) == 0) {
            $GLOBALS['badge_ids'] = array();
        }
        echo $badge_id; // WONT PRINT, IS NULL
        array_push($GLOBALS['badge_ids'], $badge_Id);
        print_r($GLOBALS['badge_ids']); // ALWAYS HAS NULL VALUES
    }


Instead of

if(count($GLOBALS['badge_ids']) == 0) {
  $GLOBALS['badge_ids'] = array();
}
echo $badge_id;

try

var_dump($badge_id); // to check what it contains at the very beginning of the function
if(!is_array($GLOBALS['badge_ids'])) {
  $GLOBALS['badge_ids'] = array();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜