我怎样才能正确地评价这个 PHP 代码? [关闭]
Posted
技术标签:
【中文标题】我怎样才能正确地评价这个 PHP 代码? [关闭]【英文标题】:How can I properly outcomment this PHP code? [closed] 【发布时间】:2013-03-22 23:46:47 【问题描述】:我有这个代码:
<?php do_action('twentytwelve_credits'); ?>
<a href="<?php echo esc_url(__('http://wordpress.org/', 'twentytwelve')); ?>"
title="<?php esc_attr_e('Semantic Personal Publishing Platform', 'twentytwelve'); ?>"
><?php printf(__('Proudly powered by %s', 'twentytwelve'), 'WordPress'); ?></a>
我应该如何评价它?
【问题讨论】:
【参考方案1】:<?php
echo 'This is a test'; // This is a one-line c++ style comment
/* This is a multi line comment
yet another line of comment */
echo 'This is yet another test';
echo 'One Final Test'; # This is a one-line shell-style comment
?>
【讨论】:
这如何回答这个问题?【参考方案2】:取决于您是否希望将 cmets 传播到浏览器:
<?php
/* This very interesting comment won't show in the content sent to the browser
*/
do_action( 'twentytwelve_credits' );
// or some end of line comment, not forwarded to the browser either
?>
<!--
But this one will
-->
<a href="<?php echo esc_url( __( 'http://wordpress.org/', 'twentytwelve' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentytwelve' ); ?>"><?php printf( __( 'Proudly powered by %s', 'twentytwelve' ), 'WordPress' ); ?></a>
【讨论】:
【参考方案3】:像这样:
<?php /*do_action( 'twentytwelve_credits' ); ?>
<a href="<?php echo esc_url( __( 'http://wordpress.org/', 'twentytwelve' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentytwelve' ); ?>"><?php printf( __( 'Proudly powered by %s', 'twentytwelve' ), 'WordPress' ); ?></a>
*/ ?>
但我通常会删除或替换整个块。
【讨论】:
【参考方案4】:在 PHP 中有多种注释方式:
/* INFO */ for multiline comments
# INFO for single-line comments
// INFO for single-line comments
【讨论】:
【参考方案5】:/* multi-line quote */
对于单行引号,只需在其前面输入一个哈希 (#
) 或双斜杠 (//
)。
【讨论】:
以上是关于我怎样才能正确地评价这个 PHP 代码? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章