|
Posted by Toby A Inkster on 04/18/07 16:31
Steve wrote:
> Toby A Inkster:
>
> | Question 1:
> |
> | <?php
> | $i = 5;
> | $i = 5 + $i++;
> | echo $i; // What does this print?
> | ?>
>
> i see you've taken the $i = $i + $i++ discussion here. you do realize this
> effects ALL c-ish languages including javascript, right? :)
Indeed I do.
> since he's betting his 'c' developers, they'll laugh that he thinks it
> is an advanced question.
The OP didn't mention of whom he was intending to ask the questions in the
original post. And even so, it's the kind of question that it's very easy
to make a mistake answering. The so called "smiple" question. Think a tonne
of lead vs a tonne of feathers.
> | Question 2:
> |
> | Which of the following is wrong? (There may be more than one
> | which are wrong.)
> |
> | * in_array($needle, $haystack);
> | * stristr($needle, $haystack);
> | * strpos($needle, $haystack);
> | * preg_match($needle, $haystack);
>
> NONE of the above are wrong. you fail to make constraints on $needle and
> $haystack in each function.
One assumes of course, that you are intending to search $haystack for
$needle. That is the normal usage of those metasyntactic variables, and it
is used consistently in the PHP documentation. Anyone not understanding
that should be failed automatically anyway.
http://en.wikipedia.org/wiki/Metasyntactic_variable#Needle_and_haystack
> | Question 3:
> |
> | Describe the output of this code:
> |
> | <?php
> | function print_defined_vars ()
> | {
> | print_r(get_defined_vars());
> | }
> | $a = 1;
> | $b = 2;
> | print_defined_vars();
> | ?>
>
> uhmmm, is this a head-scratcher?
Nope. But it's more fun to pick an innocuous looking question with a
gotcha that they might not spot, than to just post an enormous 1000 line
chunk of impenetrable code and say "find the syntax error in that".
--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Navigation:
[Reply to this message]
|