Req #80844 [Nab]: Array destructuring for mysqli_result
| From: | olafvdspek at gmail dot com | Date: | Mon, 08 Mar 2021 16:15:28 +0000 |
| Subject: | Req #80844 [Nab]: Array destructuring for mysqli_result | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232627@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80844&edit=1
ID: 80844
User updated by: olafvdspek at gmail dot com
Reported by: olafvdspek at gmail dot com
Summary: Array destructuring for mysqli_result
Status: Not a bug
Type: Feature/Change Request
Package: MySQLi related
Operating System: *
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I like code to be as simple as possible, having to repeat the code is less simple than is possible..
The inconsistency with PDO seems weird too.
Previous Comments:
------------------------------------------------------------------------
[2021-03-08 15:26:25] requinix@php.net
Making the iterator return a different kind of array would be a breaking change for code that thinks
the array is purely associative.
Is it really such a problem to destructure with keys?
------------------------------------------------------------------------
[2021-03-08 14:14:56] olafvdspek at gmail dot com
I know.. hence my feature request (to support destructuring without keys).
------------------------------------------------------------------------
[2021-03-08 13:43:57] requinix@php.net
As you can see, the value given through the iterator is an array that contains only associative
string keys, not also numeric keys. It can be destructured - if you specify the keys.
...as ["uid" => $uid, "name" => $name]
------------------------------------------------------------------------
[2021-03-08 10:07:57] rtrtrtrtrt at dfdfdfdf dot dfd
RTFM
https://www.php.net/manual/en/mysqli-result.fetch-array.php
resulttype
This optional parameter is a constant indicating what type of array should be produced from the
current row data. The possible values for this parameter are the constants MYSQLI_ASSOC, MYSQLI_NUM,
or MYSQLI_BOTH.
By using the MYSQLI_ASSOC constant this function will behave identically to the
mysqli_fetch_assoc(), while MYSQLI_NUM will behave identically to the mysqli_fetch_row() function.
The final option MYSQLI_BOTH will create a single array with the attributes of both.
------------------------------------------------------------------------
[2021-03-08 10:01:34] olafvdspek at gmail dot com
// mysqli
Array
(
[uid] => 1
[name] => Alpha
)
// PDO
Array
(
[uid] => 1
[0] => 1
[name] => Alpha
[1] => Alpha
)
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=80844
--
Edit this bug report at https://bugs.php.net/bug.php?id=80844&edit=1