PHP:如何跳过注释?
好吧,如果我评论一些东西,它在所有语言中都被跳过了,但是它们是如何被跳过的,读什么呢 例如:PHP:如何跳过注释?,php,language-design,comments,Php,Language Design,Comments,好吧,如果我评论一些东西,它在所有语言中都被跳过了,但是它们是如何被跳过的,读什么呢 例如: // This is commented out 现在PHP是读取整个注释以转到下一行,还是只读取/ 脚本被解析并拆分为标记 实际上,您可以自己在任何有效的PHP源代码上使用,它使用PHP的本机标记器 手册中的示例显示了如何处理注释: <?php $tokens = token_get_all('<?php echo; ?>'); /* => array(
// This is commented out
现在PHP是读取整个注释以转到下一行,还是只读取
/
脚本被解析并拆分为标记
实际上,您可以自己在任何有效的PHP源代码上使用,它使用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 */'));
?>
普通文件中的标记*/
$tokens=token_get_all('/*comment*/');
//=>数组(数组(T_INLINE_HTML,'/*comment*/');
?>
编译时有一个标记化阶段。在这个阶段,它会看到//并忽略行末尾的所有内容。编译器可能会变得复杂,但在大多数情况下都非常简单
你的问题毫无意义。在读了“/”之后,它必须继续读新行才能找到它。这是别无选择的。没有其他方法可以找到新线 从概念上讲,编译在解析之前有几个阶段: