I have this code:
<?php
function f() {
return 5;
}
$a = 5;
And I am using NetBeans 8.2 with PSR-1 compatibility check turned on. And I am getting this error:
Why is that and how can I fix it?
The PSR-1 standard states that
Files SHOULD either declare symbols (classes, functions, constants, etc.) or cause side-effects (e.g. generate output, change .ini settings, etc.) but SHOULD NOT do both.
This means if you have function or class definitions in a file, you shouldn't have code with side-effects (like a variable assignment) outside these definitions within the same file.
So
function f() {
return 5;
}
and
$a = 5;
should be separated into different files.