Welcome Guest, Not a member yet? Register   Sign In
Does CI performs extra parsing on the PHP code?
#1

[eluser]tlam[/eluser]
I'm currently using PHP 5.2.6 and the following type of codes pass fine:

Code:
function check()
{
    if (some_boolean())
        $output = 'hello';

    return $output;
}

I know the above is not good because $output should have been defined before the if statement but there are lots of legacy codes like the above. It seems that CI is performing additional parsing and I am getting the following type of errors:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: output

Filename: helloworld.php

Line Number: 10


Is there a way to tell CI to stop performing that additional parsing?
#2

[eluser]CroNiX[/eluser]
Sure there is, you need to code a little better. You are getting that notice because you are defining a variable within a conditional statement which might not occur and if it doesn't, you are returning an undefined variable. It has nothing to do with CI, this is a php notice.

Code:
function check()
{
    $output = '';  //define output
    if (some_boolean())
        $output = 'hello';

    return $output;
}
#3

[eluser]jedd[/eluser]
I think that was tlam's point.

I went and wrote comparable code outside of CI, and as tlam suggested, the error doesn't manifest - it just doesn't return anything (or perhaps it returns NULL - I didn't test that far).

CI does appear to be either bumping up the error reporting sensitivity, or doing something else a bit funny. Unless it's just something that happens within classes only - I didn't test that either.
#4

[eluser]CroNiX[/eluser]
Does your comparable outside code have E_NOTICE turned off? I don't think you can turn just E_NOTICE off from the CI Exception handler which is what is causing the problem I believe.
#5

[eluser]jedd[/eluser]
Ah, cool, there's the answer.

Just set error_reporting(8); in my non-CI test script, and yes, it starts to throw an error when it hits an undefined variable now.
#6

[eluser]tlam[/eluser]
I noticed that error_reporting() is set to E_ALL only in the index.php file of the root folder of CI. I can re-configure it to match my server's options.




Theme © iAndrew 2016 - Forum software by © MyBB