How to reproduce the above Notice:
A message appears when you send an empty array to a function like: echo or print :
php> print(array(1,2,3)) PHP Notice: Array to string conversion in /usr/local/lib/python2.7/dist-packages/phpsh/phpsh.php(591) : eval()'d code on line 1 Array
In this case, echo and print will simply print Array to stdout and then write the notification to stderr.
In more detail you can do this in a php script:
Create a PHP array and try printing an empty array in stdout:
<?php $stuff = array(1,2,3); print $stuff;
Correction 1: use the built-in php function print_r or var_dump:
http://php.net/manual/en/function.print-r.php
http://php.net/manual/en/function.var-dump.php
$stuff = array(1,2,3); print_r($stuff); $stuff = array(3,4,5); var_dump($stuff);
Print
Array ( [0] => 1 [1] => 2 [2] => 3 ) array(3) { [0]=> int(3) [1]=> int(4) [2]=> int(5) }
Correction 2: use json_encode to collapse the array into a json string:
$stuff = array(1,2,3); print json_encode($stuff);
Correction 3: Merging all the cells in the array:
<?php $stuff = array(1,2,3); print implode(", ", $stuff);
Correction 4: notification suppression:
error_reporting(0); print(array(1,2,3));
Why is this happening?
If you study the php documentation for print and echo,
http://php.net/manual/en/function.print.php
http://php.net/manual/en/function.echo.php
You will see that both take strings, not arrays. You pass the array as a string, in general, when you make such errors, PHP will not do anything or will do something very unexpected.