Adding a new mysqli::bind_value method

From: Date: Sun, 05 May 2013 13:55:34 +0000
Subject: Adding a new mysqli::bind_value method
Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
I propose to add, contrary to the mysqli::bind_param method which accepts parameters only by ref
(and triggers a fatal error when passing non-ref variables or values), a mysqli::bind_value method
which accepts the variables by value.

There are a few problems when using bind_param which bind_value tries to solve:

a) When you aren't binding in a small scope, you have to make attention to not reusing the
variable before execute()'ing the mysqli_stmt instance.
b) You have to pass values per reference, so that you cannot do for example in a function:
          call_user_func_array([$stmt, "bind_param"],
array_merge([str_repeat("s", func_num_args())], func_get_args()));
     this would fail in a message you couldn't pass them by value (when you cannot write the
function expecting references as variable for some reason). A workaround would be to array_walk the
array and pass the variable by ref to a new array, which is not really handy.
c) When you try to pass raw values instead of a reference, it results in a "Fatal error: 
Cannot pass parameter 2 by reference".   
d) Executing $stmt->bind_param("s", $a?$b:$c); would result in a "Strict
Standards: Only variables should be passed by reference". Yeah, it's only a strict error,
but I think it's best practice to code error free...

For c) and d): Yes, you could assign the result / raw value to a variable and then pass it to the
function, but this are only a variable more, a code line more and a fraction of a nanosecond more
(microoptimization, I just wanted to say it).

The PR for this request is at: https://github.com/php/php-src/pull/338

Bob



Thread (1 message)

  • Bob Weinand
« previous php.internals (#67310) next »