arrays - Unexpected behaviour in PHP Altorouter when passing parameters -
setup
i'm accessing url: <host>/render/z63034/rblr/glzb
.
my url pattern such: /render/[a:title]/[a:bpfrom]/[a:bpto]
.
my route gets added so:
$router->map("get", "/render/[a:title]/[a:bpfrom]/[a:bpto]", function ($params) { include __dir__ . "/views/render.php"; }, "render");
the call looks this:
call_user_func_array($match['target'], $match['params']);
in index.php
(where requests routed to) var_dump()
of $match['params']
yields expected:
array(3) { ["title"]=> string(6) "z63034" ["bpfrom"]=> string(4) "rblr" ["bpto"]=> string(4) "glzb" }
in render.php
(which included) var_dump()
of $params
yields unexpected
string(6) "z63034"
question
why first element in array i'm passing call_user_func_array
passed (not array, value itself)?
notice call_user_func_array
passes $params
single parameters, mean, in function definition, have declare parameters $params
array has.
for example if call this:
$params = array('hello', 'world'); call_user_func_array(array($this,'test'), $params);
and function definition looks that
function test($a){ echo $a; echo $b; echo '<br>'; }
you print 'hello', have declare function this
function test($a, $b){ echo $a; echo $b; echo '<br>'; }
hope helps
Comments
Post a Comment