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

From: Date: Sat, 19 Dec 2020 14:18:08 +0000
Subject: Bug #80532 [Opn->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-231170@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 Updated by: cmb@php.net Reported by: Srglmr at gmail dot com Summary: assigning value to string at high index(1e9) results in out of memory error -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: windows 10 & CentOS 7 PHP Version: 7.3.25 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: 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> Previous Comments: ------------------------------------------------------------------------ [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 (#231170) next »