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 :)

Community
  • 1
  • 1
sineverba
  • 5,059
  • 7
  • 39
  • 84
  • 1
    @Virus721 I can't agree; OOP in PHP is wonderful, especially since SPL implementations and PHP 5.5 – Daniel W. Oct 22 '13 at 09:11
  • That's not OOP, that's cheating :o PHP is natively flawn and misconcepted. – Virus721 Oct 22 '13 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. – dbf Oct 22 '13 at 12:27

1 Answers1

1

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

morgoth84
  • 1,070
  • 2
  • 11
  • 25