PDA

View Full Version : PHP parameters issue



jairoh_
August 13th, 2013, 10:23 AM
i'm basically building a framework to test myself in and i'm starting to freak out. And might as well need a help.

i have a config file that accepts the url and get the value passed ex. "display/jairoh/5/3".
now i have the values (jairoh,5 and 3) in an array.
the problem is how can i call the function when the parameters are dinamic?
i mean controller->display( 'jairoh', 5, 3 );, it calls the function display( $username, $id, $anotherval ),
does it mean i have to do controller->display(arr[1], arr[2], arr[3] );?and add another arr[4] if i add a 4th parameter in my function, or 5th or 6th?

i just want it to be dinamic. w/out passing an array of values but arguments. tnx :)

DarkAmbient
August 13th, 2013, 12:27 PM
Why not just design the display-function to take an array?


controller->display($arr)

or pass by reference.


controller->display(&$arr)

jairoh_
August 14th, 2013, 01:22 PM
Why not just design the display-function to take an array?


controller->display($arr)

or pass by reference.


controller->display(&$arr)

are there no other ways than specifying an array? tnx

DarkAmbient
August 14th, 2013, 03:22 PM
Another option would be

func_num_args() returns # of parameters provided to function.


func_get_args() returns an array holding all parameters provided to function.

Still, not much difference than supplying the function with an array from start.

Otherwise idk.. I havn't touched PHP in several years.

jairoh_
August 14th, 2013, 11:06 PM
Another option would be

func_num_args() returns # of parameters provided to function.


func_get_args() returns an array holding all parameters provided to function.

Still, not much difference than supplying the function with an array from start.

Otherwise idk.. I havn't touched PHP in several years.
thankyou sir for the effort trying to help. i end up using RelefectionMethod's getNumberOfParameters http://php.net/manual/en/class.reflectionmethod.php

DarkAmbient
August 15th, 2013, 12:27 AM
Glad it worked out for you =)