#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    Creating default object from empty value


    Hi, I'm getting this error and I can't find a solution. This piece of code causes it:
    PHP Code:
    function bp_group_hierarchy_setup_globals() {
        global 
    $bp$wpdb;

        
    /* For internal identification */
        
    $bp->group_hierarchy->id 'group_hierarchy'// error line
        
    $bp->group_hierarchy->table_name $wpdb->base_prefix 'bp_group_hierarchy';
        
    $bp->group_hierarchy->slug BP_GROUP_HIERARCHY_SLUG;
        
        
    /* Register this in the active components array */
        
    $bp->active_components[$bp->group_hierarchy->slug] = $bp->group_hierarchy->id;
        
        
    do_action('bp_group_hierarchy_globals_loaded');

    That code is from BuddyPress. I have nothing to do with it.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    sorry, but contrary to popular belief, we're not psychic -- nor do we know that "BuddyPress" (at least I don't).

    So what is "this error"? If PHP is telling you that $bp isn't an object, see where $bp is defined. If $bp is the "main controller" ($bp = BuddyPress?), this might be a deeper problem.

    But I'm just throwing out guesses here. Without concrete info, we cannot help you.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    Sorry, I'm a total newbie at PHP. This is the error:
    Code:
    Warning: Creating default object from empty value in C:\XAMPP\htdocs\hidden\wp-content\plugins\bp-group-hierarchy\bp-group-hierarchy-actions.php on line 22
    The file is only about 90 lines and that function is the only place where $bp is defined.

    I have found a temporary solution, but it doesn't really fix the problem. I added "ini_set('display_errors', 0);" to wp-config.php to hide the warnings, but I really want to fix them, not hide. I hope someone has the solution.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Also sorry from my part. I didn't know that error message (I thought this would throw a "non-object" error), so I didn't realize you included it in the thread title.

    Are you sure $bp doesn't exist anywhere, not even in an included file? If that's the case, there's defininitely something wrong. Maybe the installation failed. Otherwise, see if you forgot to include the script which defines $bp.

    You're right that the error needs to be fixed. If $bp doesn't exist, any action with this object has no effect (PHP simply creates a blank object), and you'll experience other problems.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    Well I did CTRL+F and that function is the only place where $bp was found. Also, there isn't anything included in that file, so I'm totally clueless where else to start seaching.

    I think the warning may be caused by the latest PHP version (5.4.7) in XAMPP because the person, who was working earlier on this project, was using some older version of PHP. But I may be wrong.
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by Stylock
    I think the warning may be caused by the latest PHP version (5.4.7) in XAMPP because the person, who was working earlier on this project, was using some older version of PHP.
    Still the variable has got to be defined somewhere. What you might also try is search for 'bp' and "bp" (including the quotes) and check the sessions, the cookies and the request data ($_SESSION, $_COOKIE, $_REQUEST). If that code is very old and very bad, it might use the infamous register_globals "feature", which would automatically create variables from user input. Since register_globals no longer exists in current versions of PHP, this might be an explanation for the bug.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    There are dozens of folders with dozens folders with dozens of files in each folder & subfolder, so I'm totally clueless what should I do next.

    Anyway, thanks for your help attempt. I will share the solution if I find it.
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by Stylock
    There are dozens of folders with dozens folders with dozens of files in each folder & subfolder, so I'm totally clueless what should I do next.
    Grab an editor which can search a text files in a folder for words (like Notepad++) and look for
    Code:
    'bp'
    as well as
    Code:
    "bp"
    This will show you "hidden" assignments like
    Code:
    GLOBALS['bp'] = ...;
    or assignments to $_SESSION.

    If you still can't find anything, put this in your script and run it:
    PHP Code:
    var_dump($_SESSION);
    var_dump($_COOKIE);
    var_dump($_REQUEST); 
    This will inspect all user data. Like I said: The old register_globals automatically created variables from the user input, so if your predecessor used it, you'll find it here.

    That's pretty much all I can think of.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    Ow, I used NetBeans search and found "$GLOBALS['bp'] = new BuddyPress;" in one of the files. What should I do now?
  18. #10
  19. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    If it's a kind of "global configuration" file, then that's what you wanna include in your script (or the script which uses it).

    I mean, you could of course just write the
    Code:
    $GLOBALS['bp'] = new BuddyPress();
    into your file, but that might not really solve the problem. Like I said earlier: This is likely to be a deeper problem. The missing $bp is probably just the symptom of a missing configuration file or something.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    I've added a tiny piece of code to that function and it fixed the warning. Like this:
    PHP Code:
    function bp_group_hierarchy_setup_globals()
    {
        global 
    $bp$wpdb;

        
    /* Define a default class if one has not been instantiated */
        
    if (!is_object($bp->group_hierarchy))
        {
            
    $bp->group_hierarchy = new stdClass();
        }
        
    /* For internal identification */
        
    $bp->group_hierarchy->id 'group_hierarchy';
        
    $bp->group_hierarchy->table_name $wpdb->base_prefix 'bp_group_hierarchy';
        
    $bp->group_hierarchy->slug BP_GROUP_HIERARCHY_SLUG;

        
    /* Register this in the active components array */
        
    $bp->active_components[$bp->group_hierarchy->slug] = $bp->group_hierarchy->id;

        
    do_action('bp_group_hierarchy_globals_loaded');

    Is that the correct way?
  22. #12
  23. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    No. This is just surpressing the error message, but it doesn't solve the problem.

    The $bp object has a specific purpose. If it doesn't exist, the code won't work. As we already found out, it does exist in another script, so it's obviously a missing "include" (or $bp doesn't get loaded).

    Again: The object is there for a reason, the programmers didn't put it into the code just for fun. You cannot replace it with a random empty object. This might surpress the error message for that particular line, but you'll run into trouble later when the object is used.

    I mean, if the fuel warning light of your car flashes, you need to refill gas, not put water into the tank to make the light stop flashing.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    I can't figure out how to include that global configuration file there. It's located two directories back. This is how everything is included in one of the files:
    PHP Code:
    require (dirname__FILE__ ) . '/achievements-classes.php'); 
    I've tried this:
    PHP Code:
    require (dirname__FILE__ ) . '../../folder/bp-loader.php'); 
    But that gives me fatal error.

    EDIT: Also, it seems to work without any bugs with that previous code that I posted.

IMN logo majestic logo threadwatch logo seochat tools logo