3

I'm trying to convert a json string into an array with php.

My php version is 7.0

I'm getting this error:

PHP Fatal error: Uncaught Error: Call to undefined function GuzzleHttp\json_decode()

Here's the code with the issue:

$adjunto1 = $value['archivo']; 
$adjunto2 = json_decode($adjunto1, TRUE); //this is teh line with the error

$value['archivo'] comes from the database, and if I see inside I get:

string(155) "{"nombre":["ejemploxls"],"archivoContenido":["id.--ejemploxls--fecha-26-04-2020-10-08.xls"],"fecha":["26-04-2020-10-08"],"size":[5632],"extension":["xls"]}"

When I converted the array to a json string using json_encode(), the array looked like this:

  array(5) {
    ["name"]=>
    string(11) "ejemplo.xls"
    ["type"]=>
    string(24) "application/vnd.ms-excel"
    ["tmp_name"]=>
    string(14) "/tmp/php7M0gVS"
    ["error"]=>
    int(0)
    ["size"]=>
    int(5632)
  }

What is this error? What is GuzzleHttp?

2
  • Seems that you have some kind of implicit import of GuzzleHttp. To solve that problem let's try to add a slash before function call: $adjunto2 = \json_decode($adjunto1, TRUE);. If you want to obtain much more detailed answer, add a list of you php-imports (use), please. Commented Apr 26, 2020 at 14:11
  • Using \ got it sorted, thank you @MaksimIakunin! Please add it as an answer, so I can accept it. Why I did an implicit import of GuzzleHttp? I didn't even know about GuzzleHttp... Commented Apr 26, 2020 at 14:18

1 Answer 1

2

Seems that you have some kind of implicit import from GuzzleHttp.

Guzzle is an extensible PHP HTTP client.

Here is a wrapper for json_decode php-function from GuzzleHttp namespace, that may cause your problem.

As a quick soluiton just add a slash before function call:

$adjunto2 = \json_decode($adjunto1, TRUE);

If you want to obtain much more detailed answer from me, plese, add a list of you use-statements from beginning of your php-file. Also list of includes (if there is any) would be helpful. I need some more context to be more precise.

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.