Page 1 of 1

What do you think of this question in the cert guide

Posted: Sat Nov 18, 2017 3:15 pm
by daan3137
Hi there,

I strongly disagree with one of the questions in the certification guide. I am curious how others think about it.

The question is:
What is the best way to test if $param is an anonymous function in a method.
A: ...
B: use is callable($param)
C: use the type hint closure on the signature
D: ...

In my opinion the answer should be B. But gotcha. According to the text book it should be C.
But, the question was how to test if a variable contains a certain type. Not how to prevent the situation. Testing suggests you are already in an uncertain situation. Also, C should not even be marked as a possible answer I would say. Because the answer is based on assumptions. Who says I can change the method signature? And even if I was allowed to change some interface ... Changing that might have impact on other parts of the software. I would not say this can be considered the better solution in many real world applications. Don't get me wrong. I love strictness. It would have been as C suggests from the beginning. But that was not the question.
Also who says $param was input? It is likely but an assumption none less. It might have been somebody preparing some $param to pass to another function?

Anyway. I strongly disagree with the claim that C is always the best solution to test if some variable called $param is callable.

I am curious to hear how others think about it.

Re: What do you think of this question in the cert guide

Posted: Mon Jan 29, 2018 8:25 am
by meo2381
yes i do (Y)