Heim  >  Artikel  >  Backend-Entwicklung  >  为什么PHP class文件后缀 可以不是.php

为什么PHP class文件后缀 可以不是.php

WBOY
WBOYOriginal
2016-08-04 09:19:02828Durchsuche

<code>include 'PhpBeautifier.inc';//为什么这个class 是.inc 结尾呢?

$beautify = new PhpBeautifier();
$beautify -> tokenSpace = true;//put space between tokens
$beautify -> blockLine = true;//put empty lines between blocks of code (if, while etc)
$beautify -> optimize = true;//optimize strings (for now), if a double quoted string does not contain variables of special carachters transform it to a single quoted string to save parsing time
$beautify -> file( 'test.php', 'beautified.php' );</code>

?>

https://github.com/easychen/L...

回复内容:

<code>include 'PhpBeautifier.inc';//为什么这个class 是.inc 结尾呢?

$beautify = new PhpBeautifier();
$beautify -> tokenSpace = true;//put space between tokens
$beautify -> blockLine = true;//put empty lines between blocks of code (if, while etc)
$beautify -> optimize = true;//optimize strings (for now), if a double quoted string does not contain variables of special carachters transform it to a single quoted string to save parsing time
$beautify -> file( 'test.php', 'beautified.php' );</code>

?>

https://github.com/easychen/L...

因为他只是标志一个文件而已,后缀你想改成任何合法的字符都可以(哪怕去掉后缀)。
PHP 在内部执行过程大概是这样:

  1. 找到文件名或路径对应的文件;

  2. 读取文件的内容;

  3. 将内容解析为 PHP 代码并执行。

所以,这和后缀是什么没太多关系,这里的后缀只是为了标识此文件的作用而已,相似的还有 XXX.tpl(模板)等

include可以包含任何类型文件,只要有权限读,比如下面这样

<code><?php include "../.gitignore";</code></code>

嗯,谢邀。前面回答都对,所以要注意include/require的安全性。

谢邀,刚看到这个问题我愣了下,include 指令用于将指定文件引入并运行(与require相同)。

require include什么类型的文本文件都可以,被引用的文件里面的内容会当做php代码执行(有

你可以require/include一个txt、html、js、css等,有的PHP木马利用这一点绕过安全工具的检测。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn