Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Encode Failed #616

Closed
austinh opened this issue Jul 24, 2015 · 4 comments
Closed

JSON Encode Failed #616

austinh opened this issue Jul 24, 2015 · 4 comments

Comments

@austinh
Copy link

austinh commented Jul 24, 2015

JSON encoding failed: Malformed UTF-8 characters, possibly incorrectly encoded. Encoding: array (

I upgraded my symfony composer files lately, and got this error. This does not happen in 1.14.0. The latest change in "Fixed JSON encoding errors being silently suppressed (PHP 5.5+ only)" caused this error.

I am using this in conjunction with SNCRedis Bundle to store sessions in redis.

Is there any way sncredisbundle can utf8_encode the log message?
The session is saved fine and everything else works, its purely the logging.
I have also created a bug at SncRedisBundle git because it may be an issue with their code.

@Seldaek
Copy link
Owner

Seldaek commented Jul 30, 2015

I believe this is usually indicating a malformed UTF-8 message yes, but maybe I made a mistake, can you link to that SncRedis issue?

@austinh
Copy link
Author

austinh commented Jul 30, 2015

snc/SncRedisBundle#193

@ckmaresca
Copy link

I don't know if this is relevant, but there are a bunch of options that you can use with json_encode to deal with odd characters that cause encoding to fail. They are described here: http://php.net/manual/en/json.constants.php - specifically JSON_HEX_* and JSON_UNESCAPED_*

I would note that this is a pain in PHP as it's not obvious that you need these options for things to work and json_encode has a habit of failing silently with no exception to trap....

@Seldaek
Copy link
Owner

Seldaek commented Nov 18, 2015

I'm gonna assume this gets fixed by #683 as there is no clear repro case I can't verify but it most likely is covered too.

@ckmaresca for the record, JSON_HEX and JSON_UNESCAPED do nothing to prevent these errors unfortunately, they merely tweak the way things are encoded by default, but that only concerns valid UTF-8 strings. Non-UTF-8 can not be encoded to json as the format mandates Unicode strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants