是否没有必要在WordPress插件PHP文件上放置一个右括号


Hello Dolly WordPress插件以一个开括号打开:<
<?php
/**
* @package Hello_Dolly
* @version 1.7.2
*/
/*
Plugin Name: Hello Dolly
Plugin URI: http://wordpress.org/plugins/hello-dolly/
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.7.2
Author URI: http://ma.tt/
*/

但是,最后一行包含

add_action( 'admin_head', 'dolly_css' );

但没有结束括号:>

PHP脚本不应该有一个右括号吗?

解析尾随的?>是微不足道的,不会产生任何明显的差异,除非每秒包含一百万个文件。

IIRC,php.net建议不要添加?>,原因如下:

  1. 没有必要
  2. 很容易意外地添加显著的?>后面的空白,将输出到客户端这反过来又可能导致模糊的"已发送邮件头"错误(这当包含的文件包含空白,并且您尝试在包含该文件后设置标头(

引用:https://softwareengineering.stackexchange.com/a/89560为什么要省略结束标记?

相关内容

最新更新