Net::Gearman and PHP 5.2.9

Tue, Apr 21, 2009 01:48 PM
I just discovered an incompatibility between Net Gearman and PHP 5.2.9+.  json_decode was changed in 5.2.9 to return NULL on invalid JSON strings.  Previously, the bare string had been returned if it was not valid JSON.  This was nice in a way as you could pass a scalar string to json_decode and not worry about it.  But, in reality, it would make debugging a nightmare for JSON.

I have updated my github fork and requested a pull into the main branch.  Once that is done a new PEAR release can be done.
Gravatar for Sean Coates

Sean Coates Says:

If I'm not mistaken, the bare string was not returned; the string was truncated at the invalid codepoint.

This caused some pretty serious headaches for me with spam comments on my blog.


Gravatar for Brian Moon

Brian Moon Says:

Perhaps if it was an actual attempt at JSON which means it did know the difference between a bare string and bad JSON and that they just broke this for fun.


$arg = "test";

echo "before:\n";

$json_val = json_decode($arg);

echo "after:\n";


string(4) "test"

string(4) "test"

Gravatar for till

till Says:

Haha... I love this bug report. I remember reading (and commenting on) it. If you read it from top to bottom -- bug, no bug, bug, patch applied. I think everyone had a different understanding of what it was supposed to do. A "real" JSON validator in ext/json would still be nice to have.

Gravatar for Aggy

Aggy Says:

Thank God! Someone with barins speaks!

Add A Comment

Your Name:

Your Email:

Your URL:

Your Comment: