var declarations, wherever they occur, are processed before any code is executed. … The scope of a variable declared with var is its current execution context, which is either the enclosing function or, for variables declared outside any function, global.
I believe the concern is the double asterisks /**
compared with common documentation examples
/*
this is a multiline comment
*/
In other words, what looks code-like @[]$ might be a comment?
For me, it looks more like information than code, but anyway…
The “C style” comment is used in various languages and AFAIK there is no standard that applies to all. I have seen comments like what is seen in documentation examples and others with “extra” asterisks. The code was fine so I assume it’s OK to do. It feels like it might be insignificantly wasteful. Once the parser sees a “/*”, every time it sees another “*” does it enter a conditional needlessly waiting for the “/” instead of moving along?
It’s a docblock to help editors that understand them, like PHPStorm. For your example it means that $files is an array (denoted by []) of SplFileInfo objects. So when you loop over the array with foreach in PHPStorm will suggest with methods you can call on each object.
Other tools, like PHPStan can also use them to check if you’re using your code correctly. When you have the annotation in your example and try to assign hello (string) to $files PHPStan will complain (rightfully) that a string is not an array of SplFileInfo objects.
It would be useful to add that PHP itself does not read those annotations and will not error when you put something in the variable that is not in line with the docblock.