Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > Passing arguments as they are received to another function
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 20th November 04:19
luigi.perroti
External User
 
Posts: 1
Default Passing arguments as they are received to another function



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!
  Reply With Quote


 


2 20th November 04:19
letssurf
External User
 
Posts: 1
Default Passing arguments as they are received to another function



You might want to take a look at
http://php.net/manual/en/function.ca...func-array.php
  Reply With Quote
3 20th November 04:19
luigi.perroti
External User
 
Posts: 1
Default Passing arguments as they are received to another function


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','bindPa ram'),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.
  Reply With Quote
4 20th November 04:19
letssurf
External User
 
Posts: 1
Default Passing arguments as they are received to another function


On the line where you have
self::$statement->call_user_func_array(array('PDOStatement','bindPa ram'),func_get_args());
try this

call_user_func_array(array(self::$statement,'bindP aram'),func_get_args());

see if that works...?
  Reply With Quote
5 20th November 04:19
luigi.perroti
External User
 
Posts: 1
Default Passing arguments as they are received to another function


Thanks, this is working fine. I only had to make the following adjustment:

$args = func_get_args();
call_user_func_array(array(self::$statement,'bindP aram'),$args);

since func_get_args as an argument is allowed only on user defined
functions.

Thank you very much for your time!

Regards,
Luigi
  Reply With Quote
Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Php 5 forum, Apache forum, Iis forum, Functions forum, Classes forum, Librarys forum, Bugs forum, Postgres forum, Mysql forum, Paradox forum, Ms sql forum, Configurations forum, Php.ini forum, Problems forum, Scripting forum, Css forum, General forums, Off-topic talk, Links, Extra forums, Php


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666