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

查看:92
本文介绍了为什么PHP class文件后缀 可以不是.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

<?php

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' );

?>

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

解决方案

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

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

  2. 读取文件的内容;

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

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

这篇关于为什么PHP class文件后缀 可以不是.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆