Wrapping php function with var args

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Wrapping php function with var args

Achmad Aulia Noorhakim
I want to wrap a php function(s) who is using func_get_arg(x) to get it's argument(s) (meaning the function have a "..." type of arg). How can I wrap this ?

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping php function with var args

MarcWeber
Excerpts from Achmad Aulia Noorhakim's message of Sat Jun 11 11:51:17 +0200 2011:
> I want to wrap a php function(s) who is using func_get_arg(x) to get it's
> argument(s) (meaning the function have a "..." type of arg). How can I wrap
> this ?

What are you asking for?

call_user_func_array('func', array('your-arg1','your-arg2'))

?

Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping php function with var args

Achmad Aulia Noorhakim
Hmm well for example, in PHP you can do this

function redirect_page() {
$url = func_get_arg(0);
if (func_num_args() == 1) {
$exit = true;
} else {
$exit = func_get_arg(1);
}
echo "<script type='text/javascript'>top.location.href='".$url."'</script>";
if ($exit) {
exit;
}
}

so basically you can have variable argument. In this particular example the function only asked for 1 argument. Now there are stuff in the PHP code that request arguments based on the 1st argument (for example if the 1st arg is 1, you ask for 2 more argument, or if the 1st arg is 2, you ask for 3 more). So it is kind of like AS3's (...) Rest argument. IIRC this also happen with facebook PHP SDK ? Have someone wrap it in haxe successfully ?

On Sat, Jun 11, 2011 at 8:59 PM, Marc Weber <[hidden email]> wrote:
Excerpts from Achmad Aulia Noorhakim's message of Sat Jun 11 11:51:17 +0200 2011:
> I want to wrap a php function(s) who is using func_get_arg(x) to get it's
> argument(s) (meaning the function have a "..." type of arg). How can I wrap
> this ?

What are you asking for?

call_user_func_array('func', array('your-arg1','your-arg2'))

?

Marc Weber

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping php function with var args

Achmad Aulia Noorhakim
2 argument really depending on the 1st argument, sorry about that, just quick copy paste :p

On Sat, Jun 11, 2011 at 9:54 PM, Achmad Aulia Noorhakim <[hidden email]> wrote:
Hmm well for example, in PHP you can do this

function redirect_page() {
$url = func_get_arg(0);
if (func_num_args() == 1) {
$exit = true;
} else {
$exit = func_get_arg(1);
}
echo "<script type='text/javascript'>top.location.href='".$url."'</script>";
if ($exit) {
exit;
}
}

so basically you can have variable argument. In this particular example the function only asked for 1 argument. Now there are stuff in the PHP code that request arguments based on the 1st argument (for example if the 1st arg is 1, you ask for 2 more argument, or if the 1st arg is 2, you ask for 3 more). So it is kind of like AS3's (...) Rest argument. IIRC this also happen with facebook PHP SDK ? Have someone wrap it in haxe successfully ?

On Sat, Jun 11, 2011 at 8:59 PM, Marc Weber <[hidden email]> wrote:
Excerpts from Achmad Aulia Noorhakim's message of Sat Jun 11 11:51:17 +0200 2011:
> I want to wrap a php function(s) who is using func_get_arg(x) to get it's
> argument(s) (meaning the function have a "..." type of arg). How can I wrap
> this ?

What are you asking for?

call_user_func_array('func', array('your-arg1','your-arg2'))

?

Marc Weber

--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping php function with var args

Justin Donaldson-3
In reply to this post by Achmad Aulia Noorhakim
You can't arbitrarily access the arguments of a function through a special variable like you can in javascript, etc.

In order to accept a variable number of parameters, you will need to specify the function to accept an array.  If you need an arbitrary number of arguments, then you can make such a function with Reflect.makeVarArgs():
http://haxe.org/api/reflect

Then, you can get the number of args with the length of the array.  You won't be able to have mixed types in the array, just Dynamic.

-Justin


On Sat, Jun 11, 2011 at 10:54 AM, Achmad Aulia Noorhakim <[hidden email]> wrote:
Hmm well for example, in PHP you can do this

function redirect_page() {
$url = func_get_arg(0);
if (func_num_args() == 1) {
$exit = true;
} else {
$exit = func_get_arg(1);
}
echo "<script type='text/javascript'>top.location.href='".$url."'</script>";
if ($exit) {
exit;
}
}

so basically you can have variable argument. In this particular example the function only asked for 1 argument. Now there are stuff in the PHP code that request arguments based on the 1st argument (for example if the 1st arg is 1, you ask for 2 more argument, or if the 1st arg is 2, you ask for 3 more). So it is kind of like AS3's (...) Rest argument. IIRC this also happen with facebook PHP SDK ? Have someone wrap it in haxe successfully ?

On Sat, Jun 11, 2011 at 8:59 PM, Marc Weber <[hidden email]> wrote:
Excerpts from Achmad Aulia Noorhakim's message of Sat Jun 11 11:51:17 +0200 2011:
> I want to wrap a php function(s) who is using func_get_arg(x) to get it's
> argument(s) (meaning the function have a "..." type of arg). How can I wrap
> this ?

What are you asking for?

call_user_func_array('func', array('your-arg1','your-arg2'))

?

Marc Weber

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org