I learned php before learning C and C++. That’s why when I found out that the developer must defined the length of an array when defining the array itself, I couldn’t understand the underlying purpose behind it. But when I started to study assembly for computer architecture, I understood that because of how stacks are formed, you have to make space for any variable before you assign value. Otherwise you may overwrite existing data or overflow the stack itself.
But my question is: Obviously we do not define the length of any element (inluding primary data types) in languages like php. So lets say we have $array = ['a', 'b', 'c']
in php. What happens when I do $array[3] = 'd'
?
Does whole stack get shifted? And if this is the case, does the whole contents of the RAM get shifet?