Re: [PHP] Passing arguments as they are received to another function
You might want to take a look at http://php.net/manual/en/function.call-user-func-array.php On Sat, Jul 12, 2008 at 4:57 PM, Luigi Perroti [EMAIL PROTECTED] wrote: Hello, I'm trying to implement a few simple wrappers for some PHP functions. Here's an example of what I'm trying to do: function myWrapper() { return defaultPhpFunction(func_get_args()); } The example above is broken since I'm just passing an array to the original function. The only way to achieve the desired result that I've found is something like this: function myWrapper() { $argsNumber = func_num_args(); if ($argsNumber == 1) { return defaultPhpFunction(func_get_arg(0)); } elseif ($argsNumber == 2) { return defaultPhpFunction(func_get_arg(0), func_get_arg(1)); } // ... // ... // ... } Since the above code is clumsy to say the least any advice would be welcome. Thanks for your time!
Re: [PHP] Passing arguments as they are received to another function
On Sat, Jul 12, 2008 at 6:00 PM, James Dempster wrote: You might want to take a look at http://php.net/manual/en/function.call-user-func-array.php Thank you very much for your suggestion. I've looked into it but I guess this doesn't work with what I'm trying to do, although what you suggested should indeed work perfectly with my previous example. Here's a snippet from the code that I'm having problems with: class MainDatabase { private static $mainDatabase = NULL; private static $statement = NULL; //... //... //... public static function prepare($query) { self::$mainDatabase-beginTransaction(); self::$statement = self::$mainDatabase-prepare($query); } public static function bindParam() { self::$statement-call_user_func_array(array('PDOStatement','bindParam'),func_get_args()); // Results in: // PHP Fatal error: Call to undefined method PDOStatement::call_user_func_array() ... // I've also tried with call_user_func_array('PDOStatement::fetchAll',func_get_args()); // but no luck, same error. } //... //... //... } I thought that a solution for the previous example would work in this scenario too, but I guess this isn't the case. Any further suggestions would be very welcome, thanks.
Re: [PHP] Passing arguments as they are received to another function
On the line where you have self::$statement-call_user_func_array(array('PDOStatement','bindParam'),func_get_args()); try this call_user_func_array(array(self::$statement,'bindParam'),func_get_args()); see if that works...? On Sat, Jul 12, 2008 at 5:36 PM, Luigi Perroti [EMAIL PROTECTED] wrote: On Sat, Jul 12, 2008 at 6:00 PM, James Dempster wrote: You might want to take a look at http://php.net/manual/en/function.call-user-func-array.php Thank you very much for your suggestion. I've looked into it but I guess this doesn't work with what I'm trying to do, although what you suggested should indeed work perfectly with my previous example. Here's a snippet from the code that I'm having problems with: class MainDatabase { private static $mainDatabase = NULL; private static $statement = NULL; //... //... //... public static function prepare($query) { self::$mainDatabase-beginTransaction(); self::$statement = self::$mainDatabase-prepare($query); } public static function bindParam() { self::$statement-call_user_func_array(array('PDOStatement','bindParam'),func_get_args()); // Results in: // PHP Fatal error: Call to undefined method PDOStatement::call_user_func_array() ... // I've also tried with call_user_func_array('PDOStatement::fetchAll',func_get_args()); // but no luck, same error. } //... //... //... } I thought that a solution for the previous example would work in this scenario too, but I guess this isn't the case. Any further suggestions would be very welcome, thanks.
Re: [PHP] Passing arguments as they are received to another function
On Sat, Jul 12, 2008 at 6:42 PM, James Dempster [EMAIL PROTECTED] wrote: On the line where you have self::$statement-call_user_func_array(array('PDOStatement','bindParam'),func_get_args()); try this call_user_func_array(array(self::$statement,'bindParam'),func_get_args()); see if that works...? Thanks, this is working fine. I only had to make the following adjustment: $args = func_get_args(); call_user_func_array(array(self::$statement,'bindParam'),$args); since func_get_args as an argument is allowed only on user defined functions. Thank you very much for your time! Regards, Luigi