Quick search:


How to avoid Reference Anomalies

First read What is a reference anomaly.

The easiest way is to avoid variable references, so if you only use php 5 phpPeanuts 2.0 is to be preferred. PhpPeanuts 1.x also had to run on php 4 and because php4 copies all objects passed or assigend by value, that is not an option. Nevertheless, if you can avoid using references with primitive values and arrays, you better do so.

Variable references are quite straigtforward as long as the variables that are referenced really exist and references are handled consequently as references. If references are assigned or passed by value and vice versa the risk of Reference Anomalies exists. To avoid them, applications running on 1.3.beta2 and higher should allways assign and pass primitive values, arrays and StringConverters by value unless there is a specific need to pass by reference (Check framework functions that (may) return objects to see if they return by reference or by value).

To help developers to avoid reference anomalies php 4.4 and 5.1 and up trigger notifications with respect to passing and assigning references. Although these notifications can not allways be avoided, it is a good idea to check your application for these notifications. For this reason PntErrorHandler (version 1.3.beta3 and up) no longer suppresses them. To make them show up you need to set your ErrorHandlers reportingLevel to E_ALL. See classSite.php for an example.