4

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:

  1. Only some strings are interned by PHP.
  2. 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.

2
  • 1
    As a rough rule, PHP interns all symbol names and string literals.
    – NikiC
    Commented Nov 30, 2020 at 10:46
  • Thank you :) Are there any specific places you could point out (maybe in php-src) where details about this "rough rule" could be studied?
    – Smuuf
    Commented Dec 1, 2020 at 14:13

0