PHP: How are the comments missing?

Well, if I comment on something that he missed in all languages, but how are they missed and what is read?

Example:

// This is commented out

Now does PHP read the entire comment to go to the next lines, or just read //?

+3
source share
3 answers

Your question does not make sense. After reading "//", he must continue reading in a new line to find it. It has no choice. There is no other way to find a new line.

Compilation conceptually has several phases, logically before parsing:

  • Scanning.
  • Screening.
  • tokenization.

(1) . (2) , . / . (3) , , . , , , .

(2). .

+1

script .

PHP, token_get_all(), PHP.

, :

<?php
$tokens = token_get_all('<?php echo; ?>'); /* => array(
                                                  array(T_OPEN_TAG, '<?php'), 
                                                  array(T_ECHO, 'echo'),
                                                  ';',
                                                  array(T_CLOSE_TAG, '?>') ); */

/* Note in the following example that the string is parsed as T_INLINE_HTML
   rather than the otherwise expected T_COMMENT (T_ML_COMMENT in PHP <5).
   This is because no open/close tags were used in the "code" provided.
   This would be equivalent to putting a comment outside of <?php ?> 
   tags in a normal file. */

$tokens = token_get_all('/* comment */'); 
// => array(array(T_INLINE_HTML, '/* comment */'));
?>
+7
+3

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


All Articles