note 123430 rejected from language.types.array by cmb
| From: | cmb@php.net | Date: | Thu, 13 Dec 2018 15:21:43 +0000 |
| Subject: | note 123430 rejected from language.types.array by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209894@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster+phpnet at sascha-ahlers dot de
----
This weird error occurs in PHP 7.1.8:
Do anybody know why this happened? At the end, it is the same logical thing, just another writing
style.
<?php
/* this will return a illegal offset type: */
$_devices = array();
$i = 0;
foreach ( $devices as $device )
{
$this->_devices[$i] = [
['path'] => '',
['included_paths'] => array(),
['excluded_paths'] => array(),
['cbytes'] => 0,
['cfiles'] => 0,
['cfolders'] => 0
];
$i++;
}
?>
<?php
/* this is basically the same result but other writing style will pass without an error, but less
good readable */
$this->_devices = array();
$i = 0;
foreach ( $devices as $device )
{
$this->_devices[$i]['path'] = '';
$this->_devices[$i]['included_paths'] = array();
$this->_devices[$i]['excluded_paths'] = array();
$this->_devices[$i]['cbytes'] = 0;
$this->_devices[$i]['cfiles'] = 0;
$this->_devices[$i]['cfolders'] = 0;
$i++;
}
?>