Dotclear use, like other applications, a lot of callback functions. However, developers made the mistake to define functions waiting for references as arguments.

Reminders :

  • With PHP argument can't be passed by reference on call time (this is deprecated for a while) but by-reference arguments are declared by the function.
  • the use of references allow the function to modify the object but also avoid copy and so improves application's performance (memory usage).

To summarize, what is used :

function OneAction (&$objet) {
function RunActions () {
call_user_func_array('OneAction', func_get_args());

The call to RunActions send a copy of myObject, and then send this value to OneAction which expect a reference.

  • With PHP ≤ 5.2.9, this is accepted and works, partialy because the behaviour wasn't the expected one, and the called function have no way to modify the object properties. This could introduce really hard to detect / fix bugs.
  • En PHP ≥ 5.3.0, this is rejected, a warning is produced, and function receive a NULL reference (rather than a copy). So this don't work anymore, but that seems cleaner and more robust.

This is explicitly written in the : scratchpad upgrade 5.3

If a function with by-reference parameters is called by value ( for example with call_user_func_array) a warning message is produced and all by-reference parameters are set to NULL. In older versions, the function was called with by value parameters.

Which solution ?

  • First solution : modify all the callback functions to not use by-reference but only by-value argument, optimization is lost and a lot of copy are done (but, this is the old unexpected result).
function OneAction ($objet) {
  • Second solution : force the RunActions to use by-reference argument, but flexibility of variable-length argument list is lost.
function RunActions (&$objet) {
call_user_func('OneAction', &$objet);

So the bug is reported upstream (of course, as often, with a patch proposal) and I'm waiting for their feedback.

To be followed..

P.S. of course, Dotclear is concerned here, but the same issue should probaly occurs in others applications.