If the memory of the link to the PHP link interpreter var suits me, PHP will create a null element in the hash table with a key similar to the one you sent, and refer to it. This can be seen by running the following test:
<?php $i = 0; $arr = []; $arrS = null; $v = memory_get_peak_usage(); for ($i = 0; $i < 150; $i++) { $arrS = &$arr[rand()]; } $v = memory_get_peak_usage() - $v; echo $v;
To the default heap size, PHP will return exactly 0 extra memory used - since it still allocates already prepared array elements (PHP keeps a few extra hash table elements empty, but is assigned to improve performance). You can see this by setting it in the range of 0 to 16 (this is the heap size!).
When you get more than 16, PHP will have to allocate additional elements and will do this on i = 17, i = 18, etc., creating null elements to refer to them.
PS: contrary to what people say, it does NOT issue an error, warning or notification. Calling an empty element without a link - no reference to a nonexistent element. Big big big difference.
source share