php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79436 Declaring Array Index
Submitted: 2020-03-30 19:15 UTC Modified: 2020-03-30 22:28 UTC
From: schmidtzilla at outlook dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.2.29 OS: LINUX cpanel
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
40 + 34 = ?
Subscribe to this entry?

 
 [2020-03-30 19:15 UTC] 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';

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-30 19:19 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: PHP Language Specification +Package: *General Issues
 [2020-03-30 19:19 UTC] 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:26 UTC] 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:39 UTC] 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 20:02 UTC] 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 22:26 UTC] datibbaw@php.net
-Status: Not a bug +Status: Feedback
 [2020-03-30 22:26 UTC] datibbaw@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.
 [2020-03-30 22:28 UTC] datibbaw@php.net
-Status: Feedback +Status: Not a bug
 [2020-03-30 22:28 UTC] datibbaw@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 00:01:27 2024 UTC