John Smith February 2016

Php, exception, is there a path which not covered?

hard to describe, given this example?

public function x()
{
    try
    {
        operation();
        return true;
    }
    catch (\Exception $e)
    {
        return false;
    }

    can this reach this line???
}

so is there a way that neither return true nor false will run? Somehow. Anyhow.

Answers


Tom Wright February 2016

You should not be able to reach the specified line.

Have you come across a case where this is happening? If so, provide some code and we can tell you why/how it is happening. If not, then your answer is no.


John Smith February 2016

explanation: I was just affraid maybe there is some kind of side effect, or something. Imagine that line:

function a()
{
    if (rand(0,1))
    {
        return true;
    }
    else
    {
        return false;
    }
    *************
}

check the stars. I know its 100% that they wont be reached - still they are there, and theoretically the construction allows that :))

if I rewrite like this:

function a()
{
    if (rand(0,1))
    {
        return true;
    }
    return false;
}

then its 101% Im sure that it wont run any uncovered block

Post Status

Asked in February 2016
Viewed 3,579 times
Voted 13
Answered 2 times

Search




Leave an answer