note 115376 deleted from language.types.array by cmb
| From: | cmb@php.net | Date: | Fri, 15 May 2015 18:35:43 +0000 |
| Subject: | note 115376 deleted from language.types.array by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-202532@lists.php.net to get a copy of this message | ||
Note Submitter: Ray.Paseur often uses Gmail
----
Array-to-String conversion by assignment or by using an array in a string context gives a string of
data that contains only the word, 'Array' and this data substitution often occurs
silently. This happens because the standard PHP installation suppresses Notice-level messages, and
the array-to-string conversion, even though it causes data loss, is only considered a Notice
condition. Here is how to discern what PHP is doing.
http://php.net/manual/en/language.types.array.php
http://php.net/manual/en/language.types.string.php#language.types.string.casting
<?php // demo/array_to_string.php
/**
* Starting with the default standard error-level of E_ALL ~ E_NOTICE
* OUTPUTS:
* Array
*/
$xyz = array('X', 'Y', 'Z');
echo $xyz;
/**
* Setting the error-level of E_ALL causes Notice messages to appear
* OUTPUTS:
* Notice: Array to string conversion in /path/to/demo/array_to_string.php on line XXX
* Array
*/
error_reporting(E_ALL);
$xyz = array('X', 'Y', 'Z');
echo $xyz;