Shoe
Shoe

Reputation: 76240

Array to string conversion on PDO::execute()

I get this error

Notice: Array to string conversion in coolFile on line 54

Now, the line 54 is the following

$result = $stmt->execute($par);

where $par is:

$par = array (
            'eNo' => $no,
            'eType' => $type,
            'eString' => $string,
            'eFile' => $file,
            'eLine' => $line,
            'eContext' => $context,
            'eTime' => time(),
            'eIp' => $_SERVER['REMOTE_ADDR']
        );

And $stmt is $stmt = $pdo->prepare($sql); and $pdo is the instance of the PDO class.

I feel a bit confused: Is PHP warning me that it has to convert an array to string? Why cannot he accept such an array in a function that expects an array to be passed as parameter?

Upvotes: 1

Views: 4705

Answers (2)

Kevin Peno
Kevin Peno

Reputation: 9196

Straight form the PHP set_error_handler page, the signature for a handler function is:

handler ( int $errno , string $errstr [, string $errfile [, int $errline [, array $errcontext ]]] )

As you can see, PHP will send you an array for context. If you don't need this, remove it or find a way to make it a scalar value.

errcontext

The fifth parameter is optional, errcontext, which is an array that points to the active symbol table at the point the error occurred. In other words, errcontext will contain an array of every variable that existed in the scope the error was triggered in. User error handler must not modify error context.

Upvotes: 1

Shoe
Shoe

Reputation: 76240

Basically it seems that the fifth parameter of set_error_handler() is an array according to the Manual:

The fifth parameter is optional, errcontext, which is an array that points to the active symbol table at the point the error occurred. In other words, errcontext will contain an array of every variable that existed in the scope the error was triggered in. User error handler must not modify error context.

So the problem was not regarding the main array, but the array inside the main array. PS: I swear i didn't know that, i was pretty sure the error context was a string.

Upvotes: 0

Related Questions