0

In according with this useful answer mysqli bind_param() expected to be a reference, value given i can create dynamic queries.

Now, i'm learning OOP but i cannot understand the correct mode to move that function, render protect and accessible from other methods.

Function is:

function refValues($arr){
    if (strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+
    {
        $refs = array();
        foreach($arr as $key => $value)
            $refs[$key] = &$arr[$key];
        return $refs;
    }
    return $arr;
}

and now i'm calling it in a Class:

class MyBaseCrud {
// other stuff

$rc = call_user_func_array(array($stmt, 'bind_param'), refValues($params));
// other stuff
}

I would learn more about OOP so i would transform in method like:

protected function refValues($array) {
    // body method
}

and after call correctly from

$rc = call_user_func_array(array($stmt, 'bind_param'), refValues($params));

of course i did try to move that function in body class

protected function refValues($arr){
    if (strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+
    {
        $refs = array();
        foreach($arr as $key => $value)
            $refs[$key] = &$arr[$key];
        return $refs;
    }
    return $arr;
}

and leave untouched

$rc = call_user_func_array(array($stmt, 'bind_param'), refValues($params));

without success.

Please, be gently... Just learning now OOP :)

3
  • 1
    @Virus721 I can't agree; OOP in PHP is wonderful, especially since SPL implementations and PHP 5.5 Commented Oct 22, 2013 at 9:11
  • That's not OOP, that's cheating :o PHP is natively flawn and misconcepted. Commented Oct 22, 2013 at 10:55
  • @Virus721 All these pointless OOP discussions when it comes to PHP's implementation of it. There is no general concept of OOP. If you are going to reference PHP to any other language that implement OOP as well then surely you can have your subjective opinion to prefer one over the other. The OOP capabilities in PHP is just another implementation on how objects will be eventually receiving messages, processing data, and sending messages to other objects just like any implementation by different programming languages try to accomplish the same. Commented Oct 22, 2013 at 12:27

1 Answer 1

1

If you are calling refValues() from within the class (from another method), you should use $this->refValues($params).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.