Bug #80532 [Nab]: assigning value to string at high index(1e9) results in out of memory error

From: Date: Sun, 20 Dec 2020 06:18:16 +0000
Subject: Bug #80532 [Nab]: assigning value to string at high index(1e9) results in out of memory error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231187@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80532&edit=1 ID: 80532 User updated by: Srglmr at gmail dot com Reported by: Srglmr at gmail dot com Summary: assigning value to string at high index(1e9) results in out of memory error Status: Not a bug Type: Bug Package: *General Issues Operating System: windows 10 & CentOS 7 PHP Version: 7.3.25 Assigned To: cmb Block user comment: N Private report: N New Comment: Thanks, it would be much better to have a notice telling me that I assigned a value at an index that is higher than my string length Previous Comments: ------------------------------------------------------------------------ [2020-12-19 14:18:08] cmb@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 It is allowed to assign by index if the variable is string[1], and the behavior is well documented[2]. Of course, you need sufficient memory (and respective memory_limit) to be able to create such large strings. [1] <https://3v4l.org/a6J2s> [2] <https://www.php.net/manual/en/language.types.string.php#language.types.string.substr> ------------------------------------------------------------------------ [2020-12-19 07:50:11] Srglmr at gmail dot com Description: ------------ $X="1"; $X[1e9]=0; // Allowed memory size of 536870912 bytes exhausted (tried to allocate 1000000032 bytes) Test script: --------------- $X="1"; $X[1e9]=0; Expected result: ---------------- i expect an error telling me that i can't assign by index if the variable is string , but instead it shows out of memory error which is very confusing error i encountered the error while trying to do something like this $S[Time()]=0; thinking that $S is an empty array ( $S = [] ) while it was a string $S = "100" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80532&edit=1

« previous php.bugs (#231187) next »