Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The warning is:
PHP Notice: Array to string conversion
When encountering an array instead of a string, implode function replaces "Array" and this is enough for me. So, the output of the function is as I want. I just want it not to issue a warning message in error.log.
How to suppress it?

details:
as an example when i run the following code:
PHP
#!/usr/bin/php

<?php
$ar = array(0, array(0, 1), 1);
$str = implode(', ', $ar);
error_log($str);
?>

i get the following output:
PHP Notice:  Array to string conversion in /home/behnama/test/php/implode.php on line 5
0, Array, 1

my question again is: how can i suppress the error message while the output is as i expect?

What I have tried:

I searched for it everywhere and found no clue.
Posted
Updated 9-Jun-18 4:22am
v2
Comments
Richard MacCutchan 9-Jun-18 9:03am    
Please edit your question and add the code that raises the error, and post the exact message and explain when it occurs.
Patrice T 9-Jun-18 9:22am    
In order to remove the secret warning, you have to do a secret correction in your secret code.
ilostmyid2 9-Jun-18 9:34am    
sorry, i thought it was clear enough. now i've updated it with an example.
Richard MacCutchan 9-Jun-18 9:44am    
Why would you think it is clear if we cannot see your code or the complete message? Those are the two most important pieces of information.
Richard MacCutchan 9-Jun-18 9:47am    
I just ran that code and did not receive the message.

1 solution

Since your question is specifically to suppress the error message, rather than fix the issue, you could use error_reporting to turn off notices:

error_reporting(E_ALL & ~E_NOTICE);

I wouldn't recommend it, but you can do it if you want to.
 
Share this answer
 
Comments
ilostmyid2 9-Jun-18 10:41am    
thx, looked for this.
after implode, i may call the function again:
error_reporting(E_ALL);
so that other errors won't be suppressed.
but essentially why this should have been an error?!...
[no name] 9-Jun-18 10:43am    
It's not actually an error, just a notice :)
It informs you that the sub-array array(0, 1) was converted to the string as "Array", which might be unexpected.
ilostmyid2 9-Jun-18 10:48am    
i expect it anyway... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900