Edit report at https://bugs.php.net/bug.php?id=79436&edit=1
ID: 79436
Updated by: datibbaw@php.net
Reported by: schmidtzilla at outlook dot com
Summary: Declaring Array Index
-Status: Not a bug
+Status: Feedback
Type: Bug
Package: *General Issues
Operating System: LINUX cpanel
PHP Version: 7.2.29
Block user comment: N
Private report: N
New Comment:
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
Previous Comments:
------------------------------------------------------------------------
[2020-03-30 20:02:04] schmidtzilla at outlook dot com
$db->exec("INSERT INTO rounds (type, starts, ends, speed, build, credits, jackpot) VALUES
($round[type], $round[starts], $round[ends], $round[speed], $round[build], $round[credits],
$round[jackpot])");
Gives it a value of 25 because $round[type] is the string 'Speed' which when echoed out
inside my exec without quotes inside of it is now fetching the default value of the databases speed
column which happened to be 25 in the database and it inserted that value into the type column! Very
much expected results! PHP is awesome! :D
------------------------------------------------------------------------
[2020-03-30 19:39:06] schmidtzilla at outlook dot com
You are correct. When I inserted into database I didn't quote the variable and it somehow game
me an unexpected result of 25.
------------------------------------------------------------------------
[2020-03-30 19:26:06] schmidtzilla at outlook dot com
If this is not a bug how would you go about assigning the value 'Speed' into the index
'type' without receiving the indexs value of 25?
------------------------------------------------------------------------
[2020-03-30 19:19:53] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
https://3v4l.org/kDjTA
------------------------------------------------------------------------
[2020-03-30 19:15:05] schmidtzilla at outlook dot com
Description:
------------
$round = [
'round' => empty($current) ? 1 : $current['round'] + 3,
'type' => 'Public',
'starts' => empty($current) ? $_SERVER['REQUEST_TIME'] :
floor($_SERVER['REQUEST_TIME'] / 86400) * 86400 + 72000,
'ends' => floor($_SERVER['REQUEST_TIME'] / 86400) * 86400 + 72000 + 864000,
'speed' => 25,
'build' => 2500,
'credits' => 4294967295,
'jackpot' => 100
];
lLater on in code..
$round = [
'round' => $current['round'] + 1,
'type' => 'Speed',
'starts' => floor($_SERVER['REQUEST_TIME'] / 86400) * 86400 + 72000,
'ends' => floor($_SERVER['REQUEST_TIME'] / 86400) * 86400 + 72000 + 172800,
'speed' => 100,
'build' => 2500,
'credits' => 0,
'jackpot' => 50
];
If the same variable is already assigned with different values 'type' =>
'Speed' now equals 25 because it's now assuming I am calling onto the variable
$round['speed'] instead of wanting the string 'Speed' and inputs it into its
place.
Expected result:
----------------
I expect the $round = [ 'type' => 'Speed' ] to put the string Speed into the
index 'type' of the $round variable instead of the value of $round['speed']
Actual result:
--------------
$round['type] = 25;
instead of
$round['type'] = 'Speed';
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79436&edit=1