Red Warnings in the editor that should be green

os: kubuntu 10.04
PhpStorm 2.0beta
build PS-98.240


The php error checking is calling this an error

$func = array('do_something', 'do_another_thing', 'do_a_third_thing');

foreach($func as $function){

     $function( $_user );

}


The script is running through each of the functions in the $func array and passing in data, but i get the error reporting saying "Function name must be a String or Closure, currently mixed."


is this an error checking issue with the system?  Is there a way i can let this not appear as a red mark?

I would also like the red mark not to appear on the !isset($flag)

foreach($array as $key => $value){
  if(!isset($flag)){
  $flag = do_something();
  }
}

currently it is firing and saying i have an "undefined variable".  Is there a way to turn the red warning off for this?

Thanks

4 comments
Comment actions Permalink

Hi Michael,

I have exactly the same issue as you do in your 2nd example. I was about to report it (because it's definitely a bug) when I saw this post. My "problematic" code looks like this:

$benchmarkMasterStarted = microtime(true);
if (!isset($benchmarkScriptStarted)) {
    $benchmarkScriptStarted = $benchmarkMasterStarted;
}

This is from master include file (lets say: include.php), which is included into the actual script (lets say: product_details.php). The "undefined variable" $benchmarkScriptStarted is actually defined in calling script (product_details.php).

PhpStorm (PS-98.271) is offering me "Resolve using PHPDOC annotation" as a way to get rid of the warning notice -- which I still think it's wrong. The code then looks like this (which does not really makes much sense to me):

$benchmarkMasterStarted = microtime(true);
/** @var $benchmarkScriptStarted TYPE_NAME */
if (!isset($benchmarkScriptStarted)) {
    $benchmarkScriptStarted = $benchmarkMasterStarted;
}

I'm about to create an ticket about the issue above.

As for the 1st example you provided: I see no errors/warnings in latest EAP (98.271). Can you try to reproduce it (that particular example) on empty project? The code below yields no warnings on my side:

function do_something($param) {
    echo $param;
}

$user = 'mySelf';
$f = array('do_something', 'do_another_thing', 'do_a_third_thing');
foreach($f as $function){
     $function($user);
}
0
Comment actions Permalink

how did you post code into here?  each time i try to reply i get "There was an error, please check below"  and my message is gone

----edit--- try moving that array out to an include file.
$user = 'mySelf';
//moved to the include file.
//$f = array('do_something', 'do_another_thing', 'do_a_third_thing');
include './junk_include.php';
foreach($f as $key => $function){
    switch($key){
        case'one':
            $function($user);
            break;
        case'two':
            $function($user);
            break;
        case'three':
            $function($user);
            break;
    }
}


and in the include file:
$f = array('do_something', 'do_another_thing', 'do_a_third_thing');



Attachment(s):
phpstorm_func_redmark1.png
phpstorm_func_redmark2.png
0
Comment actions Permalink

Hi Michael,

how did you post code into here?

That is done via "quote" button: type the text, select it & click the button.


I have tried your code: If $f is defined in the same file then no errors is shown. But if it defined in separate file and included via include/require (as in your example) then first occurrence of $function() (in case'one': block) is marked as error. Only first occurrence: the 2nd and the 3rd are fine. If you comment it out, then the 2nd (and only) being marked as error (so it's a bit different to what you had on screenshots in your real project, but that is understandable).

Because we have such different behaviour for pretty much the same code (the only difference that one variable is defined in include file which is parsed/included fine) -- this is considered a bug and should be reported as such.

0

Please sign in to leave a comment.