PHP variables reference and memory usage

后端 未结 2 1609
我寻月下人不归
我寻月下人不归 2020-12-11 16:05

According to php manual:


// Note:
// $a and $b are completely equal here. $a is not pointing to $b or vice versa.
// $a and $b          


        
相关标签:
2条回答
  • 2020-12-11 16:20

    PHP does not duplicate on assignment, but on write. See Copy-on-Write in the PHP Language (Jan 18 2009; by Akihiko Tozawa, Michiaki Tatsubori, Tamiya Onodera and Yasuhiko Minamide; PDF file) for a scientific discussion of it, Do not use PHP references (Jan 10, 2010; by Jan Schlüter) for some fun and my own take is References to the Max with more references.

    0 讨论(0)
  • 2020-12-11 16:28

    PHP uses copy-on-write so it won't use more memory for the duplicated strings until you modify them.

    0 讨论(0)
提交回复
热议问题