2

I am just starting to use Netbeans (NetBeans IDE 7.4 (Build 201310111528)). It took a long time to set up but I cannot for the life of me figure out why undefined variables don't get highlighted for PHP and Javascript. I went under options>hints> Language:PHP, and made sure Unitialized Variables was checked off, and Show As:Warning (Check Variable initalized by reference was off). Some errors get properly highlighted while the undefined variables get nothing. Here's an example with a simple program:

<?php

$b=$g+$g; //no error
$a=$sadfhasdf8adhfieiofwffsd; //no error

; //empty statement error
a=a; //syntax error
?>

The weird thing is that if I switch to Java, everything works:

public class JavaApplication2 {
public static void main(String[] args) {
   int a=22;
   int b= a*c; //cannot find symbol "c" correctly working
   }
}

1 Answer 1

3

Here's how it works in Netbeans 7.4 and 8.0 Beta:

<?php
// Example 1
$foo = $bar;  // DOES NOT give "Variable $bar seems to be uninitialized" error.

// Example 2 
function do_something_function () {
    $foo = $bar;  // Gives "Variable $bar seems to be uninitialized" error.
}

// Example 3
class foo {
    public static function do_something_method () {
        $foo = $bar;  // Gives "Variable $bar seems to be uninitialized" error.
    }
}
?>

In other words, it will flag the error within a function or method (examples 2 and 3), but not within the global space (example 1).

This is the behavior with Netbeans 7.4 and 8.0 Beta -- but I don't think that's always been the case. I'm not sure when it switched. I've been using Netbeans for years and only recently noticed that it works like this now.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm a little late, but thank you very much for your help! Wish I could give you upvote, but too new at stackoverflow too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.