Page 1 of 2

PHP function "empty" bugged?

PostPosted: November 29th, 2013, 10:56 pm
by johnc
We're using BuddyPress and experiencing problems. When diving into the code I discovered this:

Code: Select all
function bp_get_groups_current_create_step() {
      global $bp;
var_dump($bp->groups->current_create_step);
      if ( !empty( $bp->groups->current_create_step ) ) {
var_dump("assigning value");
         $current_create_step = $bp->groups->current_create_step;
      } else {
var_dump("assigning blank");
         $current_create_step = '';
      }
var_dump($current_create_step);
      return apply_filters( 'bp_get_groups_current_create_step', $current_create_step );
   }


The var_dump calls are mine. When $bp->groups->current_create_step is non-empty the else branch is still executed and $current_create_step results as a blank string.

Re: PHP function "empty" bugged?

PostPosted: November 30th, 2013, 2:42 pm
by Jakub Misek
Hi,

it may be a bug in "empty". What is the value of $bp->groups->current_create_step?

Thanks,

Re: PHP function "empty" bugged?

PostPosted: November 30th, 2013, 7:20 pm
by johnc
string(13) "group-details"

Re: PHP function "empty" bugged?

PostPosted: December 1st, 2013, 1:39 pm
by Jakub Misek
ok, thats weird, could you try more var_dumps whether everything else is as it is expected?

Re: PHP function "empty" bugged?

PostPosted: December 1st, 2013, 8:18 pm
by johnc
What do you want var_dumps of? There's only one value involved in this function.

Re: PHP function "empty" bugged?

PostPosted: December 2nd, 2013, 4:01 pm
by Jakub Misek
At least the output of the script. Does it really output "assigning blank" ?

Thanks,

Re: PHP function "empty" bugged?

PostPosted: December 9th, 2013, 4:55 pm
by johnc
The code pasted outputs:

Code: Select all
string(13) "group-details"
string(15) "assigning blank"
string(0) ""

Re: PHP function "empty" bugged?

PostPosted: January 2nd, 2014, 1:23 pm
by Jakub Misek
sorry for the delay, but this is weird. I can't replicate the issue.

The code sample you've provided above, is it a console app? Could you attach compiled EXE/DLL or the complete project?

Thank you,

Re: PHP function "empty" bugged?

PostPosted: January 17th, 2014, 3:43 am
by johnc
Sorry, I've been away for holidays.

The code is from BuddyPress, a WordPress plugin.

Re: PHP function "empty" bugged?

PostPosted: January 17th, 2014, 5:40 am
by johnc
So I spent a bit of time tonight trying to write a reproduction of the issue and completely failing.

I have managed to write a workaround hack: I replaced all calls to empty with calls to a custom PHP function, which in turn calls a method in a C# compiled DLL, which finally calls the static PHP.Core.PhpVariable.IsEmpty. I'm not sure if the call through the custom PHP function is required or not but it does work this way.