2

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) {
        if(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
    }
3
  • 3
    You realise you have $badge_Id ... should be $badge_id Commented Apr 12, 2011 at 18:25
  • $badge_Id or $badge_id? You've made this error in a couple of places. Perhaps consider using a clearer font in your text editor. Commented Apr 12, 2011 at 18:29
  • That was the answer, incorrect case!!!!!!! Commented Apr 12, 2011 at 20:35

1 Answer 1

2

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

Comments

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.