How to comment a line containing * /

I have a line of PHP source code that I would like to leave as a comment in the PHP file, so it can be used when necessary. This is only a debug script, so saving the file is not a problem.

However, I am trying to comment on these lines using /* and */ :

 /* $path = FOLDER . "*/*/*/*/*.gif"; $files = glob($path); */ 

But this result occurs when the parsing error occurs because the path */*/*/ closes the comment block. Opening /* will not be considered as an open comment inside the line, but since the commented code is not parsed, */ considered as a final comment.

Can anyone think of a workaround without using // ?

+4
source share
5 answers

use "*/*/*/*/*.gif" slashes as DIRECTORY_SEPARATOR constants?

 $path = FOLDER . '*' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . '.gif'; 

You can make a shortcut, for example define('DS', DIRECTORY_SEPARATOR);

+5
source

Just use backslash \ before doing forwardlash / . This will not affect the file path, but will make line blocks invisible.

+1
source

You will need to use // or suggest a method, such as a message or bluegman991.

"Style C comments" end on the first * / met. 1

The interpreter ends the comment in the first */ regardless of whether it is part of a line or a nested comment.

Your IDE may have a shortcut to switch // comments to blocks of code. For example, Eclipse uses Ctrl + Shift + C to switch comments to blocks of code.

+1
source

for any special character you want to use inside a string that you can use \ without affecting the behavior of that string

0
source

I personally often use:

 if (false) { ...code to be skipped... } 

Thus, you should avoid the problem, but there is not enough allocation from your ide (if it is not a very very smart ideal :))

0
source

Source: https://habr.com/ru/post/1412863/


All Articles