Variable not defined in function

Hi

I have a function in PHP. Inside the function I used a variable. The variable is not declared, and has not been received as a parameter (a programming error). I use the variable in a string concatenation operation, without initializing, and PHPStron no generate any warning. How I can set PhpStorm to generate a warning ?

 

Kind regards

jalonsoc

4 comments
Comment actions Permalink

Hi there,

Please provide a code sample (as a text so it can be copy-pasted) as well as screenshot of how it looks on your screen (preferably using Default color schema).

In my sample code such variable is highlighted.

0
Comment actions Permalink

Hi

This is the function

 

public function insertInfoLog($usuario,$aplication, $modulo, $function, $session, $ex, $errMessageBD ){

$fecha = (string)date("Y-m-d H:i:s");
$fp = fopen($this->path . $this->filename,"a");

//Escribimos el documento de errores
fwrite($fp,"***************************************************".PHP_EOL . $fecha . PHP_EOL . "Usuario: " . $usuario .
"Aplicación: " . $aplication . PHP_EOL . "Módulo: " . $modulo . PHP_EOL . "Función: " . $function . PHP_EOL .
"Mensaje error: " . $errMessage. PHP_EOL . "Mensaje error BD: " . $errMessageBD . PHP_EOL );
// Guardamos las variables de sesión

$i=0;
foreach ($session as $key => $value) {
fwrite($fp, $key . ":" . $value.PHP_EOL);
if(is_array($value)){
foreach ($value as $k => $v){
fwrite($fp, $k . ":" . $v.PHP_EOL);
}
}elseif(is_object($value)){
foreach ($value as $k => $v){
fwrite($fp, $k . ":" . $v.PHP_EOL);
}
}
//fwrite($fp, $key . ":" . $value.PHP_EOL);
}
// Guardamos toda la información de la excepción
foreach ($ex as $key => $value) {
fwrite($fp, $key . ":" . $value.PHP_EOL);
}
fwrite($fp, "***************************************************".PHP_EOL );
fclose($fp);
}

The variable $errMessage  is used, but it has not been received as a parameter.

This is the screen:

Kind regards

Justo Alonso

 

 

 

 

0
Comment actions Permalink

Thanks for the info.

It works just fine for me -- tested in 2016.2.1 as we as 2016.3 EAP

Please go to "Settings/Preferences | Editor | Inspections | PHP | Undefined" and ensure that "Undefined variable" inspection is fully enabled and has Warning severity.

 

If it's all good there then please show your settings of the above.

Maybe it needs more code to be reproducible? Try this fragment (a class with that method only) in brand new empty project -- will it behave the same?

0
Comment actions Permalink

Hi Andriy.

Problem solved. I have enabled "Undefined inspection variable".

 

Thanks and regards

Justo

 

0

Please sign in to leave a comment.