Copy-on-write in the PHP language

PHP is a popular language for server-side applications. In PHP, assignment to variables copies the assigned values, according to its so-called copy-on-assignment semantics. In contrast, a typical PHP implementation uses a copy-on-write scheme to reduce the copy overhead by delaying copies as much as possible. This leads us to ask if the semantics and implementation of PHP coincide, and actually this is not the case in the presence of sharings within values. In this paper, we describe the copy-on-assignment semantics with three possible strategies to copy values containing sharings. The current PHP implementation has inconsistencies with these semantics, caused by its naïve use of copy-on-write. We fix this problem by the novel mostly copy-on-write scheme, making the copy-on-write implementations faithful to the semantics. We prove that our copy-on-write implementations are correct, using bisimulation with the copy-on-assignment semantics.

[1]  F. Warren Burton,et al.  A New Method for Functional Arrays , 1997, J. Funct. Program..

[2]  Mark N. Wegman,et al.  Efficiently computing static single assignment form and the control dependence graph , 1991, TOPL.

[3]  Adrienne G. Bloss Update analysis and the efficient implementation of functional aggregates , 1989, FPCA.

[4]  Zhenyu Qian,et al.  A formal specification of Java class loading , 2000, OOPSLA '00.

[5]  Yasuhiko Minamide,et al.  Static approximation of dynamically generated Web pages , 2005, WWW '05.

[6]  Mirko Viroli,et al.  On Variance-Based Subtyping for Parametric Types , 2002, ECOOP.

[7]  Jacob T. Schwartz,et al.  Optimization of Very High Level Languages - I. Value Transmission and Its Corollaries , 1975, Comput. Lang..

[8]  Martin Odersky,et al.  How to make destructive updates less destructive , 1991, POPL '91.

[9]  Philip Wadler,et al.  Once upon a type , 1995, FPCA '95.

[10]  Giuseppe Castagna,et al.  Covariance and contravariance: conflict without a cause , 1995, TOPL.

[11]  Henry G. Baker,et al.  Shallow binding in Lisp 1.5 , 1978, CACM.

[12]  G BakerHenry Shallow binding in Lisp 1.5 , 1978 .

[13]  Annika Aasa,et al.  An efficiency comparison of some representations of purely functional arrays , 1988, BIT Comput. Sci. Sect..

[14]  Natarajan Shankar,et al.  Static Analysis for Safe Destructive Updates in a Functional Language , 2001, LOPSTR.

[15]  Marko C. J. D. van Eekelen,et al.  Term Graph Rewriting , 1987, PARLE.

[16]  M. Hofmann A Type System for Bounded Space and Functional In-Place Update , 2000, Nord. J. Comput..

[17]  Philip Wadler,et al.  Linear Types can Change the World! , 1990, Programming Concepts and Methods.

[18]  E. Barendsen,et al.  Graph Rewriting and Copying , 1992 .

[19]  Paul Hudak,et al.  The aggregate update problem in functional programming systems , 1985, POPL.

[20]  Arch D. Robison The Illinois functional programming interpreter , 1987, PLDI.

[21]  Jean-Christophe Filliâtre,et al.  A persistent union-find data structure , 2007, ML '07.