I was trying to get a better understanding of PHP's internal mechanisms of string interning - more specifically:
What are the rules PHP uses to determine whether (or not) the string created in userland will be interned...?
I see two possibilities:
- Only some strings are interned by PHP.
- PHP interns all strings.
For example - in Python (cpython) some, but not all strings are interned automatically (according to the Internet: http://guilload.com/python-string-interning/ or https://python-reference.readthedocs.io/en/latest/docs/functions/intern.html, to give some examples of sources I found).
I was trying to find some info about how PHP determines if the string from userland will be interned or not (I somehow expect that strings several megabytes in size are probably excluded from interning - but are they really...?) - but I couldn't find any.
I found this page http://www.phpinternalsbook.com/php7/internal_types/strings/zend_strings.html, but I don't see any mention about specific rules about automatic interning.
My Answer:
In PHP, all strings created in userland are automatically interned. This means that PHP will automatically store only one copy of each unique string in memory, regardless of its size. This helps to optimize memory usage and improve performance by reducing the amount of duplicate strings that need to be stored. So, there are no specific rules or limitations on which strings are interned in PHP - all strings created in userland will be interned automatically.
Rate this post
4 of 5 based on 2367 votesComments