arguments - I am trying to solve a PHP exercise but am unable to understand what's happening -
first of i'm sorry irrelevant question title, did not know how write better.
to start with, php beginner. solving php exercise , came upon question don't know start with:
function q3() { // supposed write stuff here , not change question right. } function a3($admin = false) { assertion_group("question 3"); foreach ($globals $k => $v) $$k = $v; if ($admin) { $file = q3("edsi.pem"); } $key = @file_get_contents($file); $key = substr($key, 0, 4); assert($key == substr(file_get_contents(__file__), 0, 4)); return $key; } first of all, understand $globals does, why assign $$k $v (so $k value $v value)? , $globals values within functions?
how can set $admin = true? believe through q3(), don't see how...
next thing confuses me most is: $file = q3("edsi.pem"). q3 function doesn't have arguments, , i'm not supposed add one, how can use that?!
thank in advance answer. apologies again vague question...
edit:
with of @mario better understand whole mess, had put in q3 was:
if ($info == 'edsi.pem') { $info = __file__; return $info; } plus add argument q3 (q3($info)) , add ?admin=true in header...
many again!
first of all, understand $globals does, why assign $$k $v (so $k value $v value)? , $globals values within functions?
what foreach … $$k = $v; snippet extract($globals);
this isn't useful way pass arguments around. using global vars makes sense if have descriptive names, , if they're not misused state flags between different code sections.
and no, globals aren't available in functions right away. read on variable scope.
how can set $admin = true? believe through q3(), don't see how...
you confusing function names here (precisely because aren't rather useful function names begin with). can pass $admin parameter when calling a3() instead:
a3(true); next thing confuses me is: $file = q3("edsi.pem"). q3 function doesn't have arguments, , i'm not supposed add one, how can use that?!
the way argument in q3 per func_get_arg().
and again really, unless exercise how not write code or tutorial weird use cases, shouldn't bother further.
Comments
Post a Comment