ThinkPHP3.2 加载过程(2)
ThinkPHP3.2 加载过程(二)
回顾:
上次介绍了 ThinkPHP 的 Index.PHP入口文件。但只是TP的入口前面的入口(刷boss总是要过好几关才能让你看到 ,不然boss都没面子啊),从Index.PHP最后一行把我们引路到了TP的大门前(ThinkPHP/ThinkPHP.php)
// 引入ThinkPHP入口文件require './ThinkPHP/ThinkPHP.php';
本次目标:
查看TP的大门,同时稍微探索一下大门内部的东西
正文:
先上代码
<span style="color: #008080;"> 1</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 记录开始运行时间</span><span style="color: #008080;"> 2</span> <span style="color: #800080;">$GLOBALS</span>['_beginTime'] = <span style="color: #008080;">microtime</span>(<span style="color: #0000ff;">TRUE</span><span style="color: #000000;">);</span><span style="color: #008080;"> 3</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 记录内存初始使用</span><span style="color: #008080;"> 4</span> <span style="color: #008080;">define</span>('MEMORY_LIMIT_ON',<span style="color: #008080;">function_exists</span>('memory_get_usage'<span style="color: #000000;">));</span><span style="color: #008080;"> 5</span> <span style="color: #0000ff;">if</span>(MEMORY_LIMIT_ON) <span style="color: #800080;">$GLOBALS</span>['_startUseMems'] =<span style="color: #000000;"> memory_get_usage();</span><span style="color: #008080;"> 6</span> <span style="color: #008080;"> 7</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 版本信息</span><span style="color: #008080;"> 8</span> <span style="color: #0000ff;">const</span> THINK_VERSION = '3.2.3'<span style="color: #000000;">;</span><span style="color: #008080;"> 9</span> <span style="color: #008080;">10</span> <span style="color: #008000;">//</span><span style="color: #008000;"> URL 模式定义</span><span style="color: #008080;">11</span> <span style="color: #0000ff;">const</span> URL_COMMON = 0; <span style="color: #008000;">//</span><span style="color: #008000;">普通模式</span><span style="color: #008080;">12</span> <span style="color: #0000ff;">const</span> URL_PATHINFO = 1; <span style="color: #008000;">//</span><span style="color: #008000;">PATHINFO模式</span><span style="color: #008080;">13</span> <span style="color: #0000ff;">const</span> URL_REWRITE = 2; <span style="color: #008000;">//</span><span style="color: #008000;">REWRITE模式</span><span style="color: #008080;">14</span> <span style="color: #0000ff;">const</span> URL_COMPAT = 3; <span style="color: #008000;">//</span><span style="color: #008000;"> 兼容模式</span><span style="color: #008080;">15</span> <span style="color: #008080;">16</span> <span style="color: #008000;">// 类文件后缀</span><span style="color: #008080;">17</span> <span style="color: #0000ff;">const</span> EXT = '.class.php'<span style="color: #000000;">; </span><span style="color: #008080;">18</span> <span style="color: #008080;">19</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 系统常量定义</span><span style="color: #008080;">20</span> <span style="color: #008080;">defined</span>('THINK_PATH') or <span style="color: #008080;">define</span>('THINK_PATH', __DIR__.'/'<span style="color: #000000;">);</span><span style="color: #008080;">21</span> <span style="color: #008080;">defined</span>('APP_PATH') or <span style="color: #008080;">define</span>('APP_PATH', <span style="color: #008080;">dirname</span>(<span style="color: #800080;">$_SERVER</span>['SCRIPT_FILENAME']).'/'<span style="color: #000000;">);</span><span style="color: #008080;">22</span> <span style="color: #008080;">defined</span>('APP_STATUS') or <span style="color: #008080;">define</span>('APP_STATUS', ''); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用状态 加载对应的配置文件</span><span style="color: #008080;">23</span> <span style="color: #008080;">defined</span>('APP_DEBUG') or <span style="color: #008080;">define</span>('APP_DEBUG', <span style="color: #0000ff;">false</span>); <span style="color: #008000;">//</span><span style="color: #008000;"> 是否调试模式</span><span style="color: #008080;">24</span> <span style="color: #008080;">25</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">function_exists</span>('saeAutoLoader')){<span style="color: #008000;">//</span><span style="color: #008000;"> 自动识别SAE环境</span><span style="color: #008080;">26</span> <span style="color: #008080;">defined</span>('APP_MODE') or <span style="color: #008080;">define</span>('APP_MODE', 'sae'<span style="color: #000000;">);</span><span style="color: #008080;">27</span> <span style="color: #008080;">defined</span>('STORAGE_TYPE') or <span style="color: #008080;">define</span>('STORAGE_TYPE', 'Sae'<span style="color: #000000;">);</span><span style="color: #008080;">28</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;">29</span> <span style="color: #008080;">defined</span>('APP_MODE') or <span style="color: #008080;">define</span>('APP_MODE', 'common'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用模式 默认为普通模式 </span><span style="color: #008080;">30</span> <span style="color: #008080;">defined</span>('STORAGE_TYPE') or <span style="color: #008080;">define</span>('STORAGE_TYPE', 'File'); <span style="color: #008000;">//</span><span style="color: #008000;"> 存储类型 默认为File </span><span style="color: #008080;">31</span> <span style="color: #000000;">}</span><span style="color: #008080;">32</span> <span style="color: #008080;">33</span> <span style="color: #008080;">defined</span>('RUNTIME_PATH') or <span style="color: #008080;">define</span>('RUNTIME_PATH', APP_PATH.'Runtime/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 系统运行时目录</span><span style="color: #008080;">34</span> <span style="color: #008080;">defined</span>('LIB_PATH') or <span style="color: #008080;">define</span>('LIB_PATH', <span style="color: #008080;">realpath</span>(THINK_PATH.'Library').'/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 系统核心类库目录</span><span style="color: #008080;">35</span> <span style="color: #008080;">defined</span>('CORE_PATH') or <span style="color: #008080;">define</span>('CORE_PATH', LIB_PATH.'Think/'); <span style="color: #008000;">//</span><span style="color: #008000;"> Think类库目录</span><span style="color: #008080;">36</span> <span style="color: #008080;">defined</span>('BEHAVIOR_PATH')or <span style="color: #008080;">define</span>('BEHAVIOR_PATH', LIB_PATH.'Behavior/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 行为类库目录</span><span style="color: #008080;">37</span> <span style="color: #008080;">defined</span>('MODE_PATH') or <span style="color: #008080;">define</span>('MODE_PATH', THINK_PATH.'Mode/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 系统应用模式目录</span><span style="color: #008080;">38</span> <span style="color: #008080;">defined</span>('VENDOR_PATH') or <span style="color: #008080;">define</span>('VENDOR_PATH', LIB_PATH.'Vendor/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 第三方类库目录</span><span style="color: #008080;">39</span> <span style="color: #008080;">defined</span>('COMMON_PATH') or <span style="color: #008080;">define</span>('COMMON_PATH', APP_PATH.'Common/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用公共目录</span><span style="color: #008080;">40</span> <span style="color: #008080;">defined</span>('CONF_PATH') or <span style="color: #008080;">define</span>('CONF_PATH', COMMON_PATH.'Conf/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用配置目录</span><span style="color: #008080;">41</span> <span style="color: #008080;">defined</span>('LANG_PATH') or <span style="color: #008080;">define</span>('LANG_PATH', COMMON_PATH.'Lang/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用语言目录</span><span style="color: #008080;">42</span> <span style="color: #008080;">defined</span>('HTML_PATH') or <span style="color: #008080;">define</span>('HTML_PATH', APP_PATH.'Html/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用静态目录</span><span style="color: #008080;">43</span> <span style="color: #008080;">defined</span>('LOG_PATH') or <span style="color: #008080;">define</span>('LOG_PATH', RUNTIME_PATH.'Logs/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用日志目录</span><span style="color: #008080;">44</span> <span style="color: #008080;">defined</span>('TEMP_PATH') or <span style="color: #008080;">define</span>('TEMP_PATH', RUNTIME_PATH.'Temp/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用缓存目录</span><span style="color: #008080;">45</span> <span style="color: #008080;">defined</span>('DATA_PATH') or <span style="color: #008080;">define</span>('DATA_PATH', RUNTIME_PATH.'Data/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用数据目录</span><span style="color: #008080;">46</span> <span style="color: #008080;">defined</span>('CACHE_PATH') or <span style="color: #008080;">define</span>('CACHE_PATH', RUNTIME_PATH.'Cache/'); <span style="color: #008000;">//</span><span style="color: #008000;"> 应用模板缓存目录</span><span style="color: #008080;">47</span> <span style="color: #008080;">defined</span>('CONF_EXT') or <span style="color: #008080;">define</span>('CONF_EXT', '.php'); <span style="color: #008000;">//</span><span style="color: #008000;"> 配置文件后缀</span><span style="color: #008080;">48</span> <span style="color: #008080;">defined</span>('CONF_PARSE') or <span style="color: #008080;">define</span>('CONF_PARSE', ''); <span style="color: #008000;">//</span><span style="color: #008000;"> 配置文件解析方法</span><span style="color: #008080;">49</span> <span style="color: #008080;">defined</span>('ADDON_PATH') or <span style="color: #008080;">define</span>('ADDON_PATH', APP_PATH.'Addon'<span style="color: #000000;">);</span><span style="color: #008080;">50</span> <span style="color: #008080;">51</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 系统信息</span><span style="color: #008080;">52</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">version_compare</span>(<span style="color: #ff00ff;">PHP_VERSION</span>,'5.4.0','<'<span style="color: #000000;">)) {</span><span style="color: #008080;">53</span> <span style="color: #008080;">ini_set</span>('magic_quotes_runtime',0<span style="color: #000000;">);</span><span style="color: #008080;">54</span> <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #008080;">get_magic_quotes_gpc</span>()? <span style="color: #0000ff;">true</span> : <span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;">55</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;">56</span> <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;">57</span> <span style="color: #000000;">}</span><span style="color: #008080;">58</span> <span style="color: #008080;">define</span>('IS_CGI',(0 === <span style="color: #008080;">strpos</span>(PHP_SAPI,'cgi') || <span style="color: #0000ff;">false</span> !== <span style="color: #008080;">strpos</span>(PHP_SAPI,'fcgi')) ? 1 : 0<span style="color: #000000;"> );</span><span style="color: #008080;">59</span> <span style="color: #008080;">define</span>('IS_WIN',<span style="color: #008080;">strstr</span>(<span style="color: #ff00ff;">PHP_OS</span>, 'WIN') ? 1 : 0<span style="color: #000000;"> );</span><span style="color: #008080;">60</span> <span style="color: #008080;">define</span>('IS_CLI',PHP_SAPI=='cli'? 1 : 0<span style="color: #000000;">);</span><span style="color: #008080;">61</span> <span style="color: #008080;">62</span> <span style="color: #0000ff;">if</span>(!<span style="color: #000000;">IS_CLI) {</span><span style="color: #008080;">63</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 当前文件名</span><span style="color: #008080;">64</span> <span style="color: #0000ff;">if</span>(!<span style="color: #008080;">defined</span>('_PHP_FILE_'<span style="color: #000000;">)) {</span><span style="color: #008080;">65</span> <span style="color: #0000ff;">if</span><span style="color: #000000;">(IS_CGI) {</span><span style="color: #008080;">66</span> <span style="color: #008000;">//</span><span style="color: #008000;">CGI/FASTCGI模式下</span><span style="color: #008080;">67</span> <span style="color: #800080;">$_temp</span> = <span style="color: #008080;">explode</span>('.php',<span style="color: #800080;">$_SERVER</span>['PHP_SELF'<span style="color: #000000;">]);</span><span style="color: #008080;">68</span> <span style="color: #008080;">define</span>('_PHP_FILE_', <span style="color: #008080;">rtrim</span>(<span style="color: #008080;">str_replace</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_HOST'],'',<span style="color: #800080;">$_temp</span>[0].'.php'),'/'<span style="color: #000000;">));</span><span style="color: #008080;">69</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;"> {</span><span style="color: #008080;">70</span> <span style="color: #008080;">define</span>('_PHP_FILE_', <span style="color: #008080;">rtrim</span>(<span style="color: #800080;">$_SERVER</span>['SCRIPT_NAME'],'/'<span style="color: #000000;">));</span><span style="color: #008080;">71</span> <span style="color: #000000;"> }</span><span style="color: #008080;">72</span> <span style="color: #000000;"> }</span><span style="color: #008080;">73</span> <span style="color: #0000ff;">if</span>(!<span style="color: #008080;">defined</span>('__ROOT__'<span style="color: #000000;">)) {</span><span style="color: #008080;">74</span> <span style="color: #800080;">$_root</span> = <span style="color: #008080;">rtrim</span>(<span style="color: #008080;">dirname</span>(_PHP_FILE_),'/'<span style="color: #000000;">);</span><span style="color: #008080;">75</span> <span style="color: #008080;">define</span>('__ROOT__', ((<span style="color: #800080;">$_root</span>=='/' || <span style="color: #800080;">$_root</span>=='\\')?'':<span style="color: #800080;">$_root</span><span style="color: #000000;">));</span><span style="color: #008080;">76</span> <span style="color: #000000;"> }</span><span style="color: #008080;">77</span> <span style="color: #000000;">}</span><span style="color: #008080;">78</span> <span style="color: #008080;">79</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 加载核心Think类</span><span style="color: #008080;">80</span> <span style="color: #0000ff;">require</span> CORE_PATH.'Think'.<span style="color: #000000;">EXT;</span><span style="color: #008080;">81</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 应用初始化 </span><span style="color: #008080;">82</span> Think\Think::start();
解释:
1 - 5 行:初始化 运行的时间 内存之类的东东,给开发人员提供代码运行效率直观上的体现
8 行:不猜也能知道 就是版本好的说明嘛
11-14行:定义4个数据嘛,也就是浏览器地址的解析模式(等一下解释)
17 行:这里不是看到是不是感觉到 我们如果加一个php时候的文件的后缀
20-49行:定义各种变量 但是下面的这段代码 其中有一个函数 get_magic_quotes_gpc() 这个函数做什么用 我大致查选了一下 大致说法 参考。TP里面 能起到多大的作用 我也不是很清楚 如果谁知道 欢迎给大家说明一下
PHP解析器就会自动为post、get、cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特别是数据库语句因为特殊字符引起的污染而出现致命的错误。
<span style="color: #008080;">1</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">version_compare</span>(<span style="color: #ff00ff;">PHP_VERSION</span>,'5.4.0','<'<span style="color: #000000;">)) {</span><span style="color: #008080;">2</span> <span style="color: #008080;">ini_set</span>('magic_quotes_runtime',0<span style="color: #000000;">);</span><span style="color: #008080;">3</span> <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #008080;">get_magic_quotes_gpc</span>()? <span style="color: #0000ff;">true</span> : <span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;">4</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;">5</span> <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;">6</span> }
最后是加载核心Think类 和运行Think类中的start()这个方法
<span style="color: #008080;">1</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 加载核心Think类</span><span style="color: #008080;">2</span> <span style="color: #0000ff;">require</span> CORE_PATH.'Think'.<span style="color: #000000;">EXT;</span><span style="color: #008080;">3</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 应用初始化 </span><span style="color: #008080;">4</span> Think\Think::start();
说明一下TP中的URL的几个模式 资料
普通模式下
1 const URL_COMMON = 0; //普通模式
URL为 http://localhost/?m=home&c=user&a=login&var=value
m参数表示模块,c参数表示控制器,a参数表示操作(当然这些参数都是可以配置的),后面的表示其他GET参数。
'VAR_MODULE' => 'm', // 默认模块获取变量
'VAR_CONTROLLER' => 'c', // 默认控制器获取变量
'VAR_ACTION' => 'a', // 默认操作获取变量
值的定义在ThinkPHP\Conf\Convention.php
<span style="color: #008080;"> 1</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 系统变量名称设置 </span><span style="color: #008000;">*/</span><span style="color: #008080;"> 2</span> 'VAR_MODULE' => 'm', <span style="color: #008000;">//</span><span style="color: #008000;"> 默认模块获取变量</span><span style="color: #008080;"> 3</span> 'VAR_ADDON' => 'addon', <span style="color: #008000;">//</span><span style="color: #008000;"> 默认的插件控制器命名空间变量</span><span style="color: #008080;"> 4</span> 'VAR_CONTROLLER' => 'c', <span style="color: #008000;">//</span><span style="color: #008000;"> 默认控制器获取变量</span><span style="color: #008080;"> 5</span> 'VAR_ACTION' => 'a', <span style="color: #008000;">//</span><span style="color: #008000;"> 默认操作获取变量</span><span style="color: #008080;"> 6</span> 'VAR_AJAX_SUBMIT' => 'ajax', <span style="color: #008000;">//</span><span style="color: #008000;"> 默认的AJAX提交变量</span><span style="color: #008080;"> 7</span> 'VAR_JSONP_HANDLER' => 'callback',<span style="color: #008080;"> 8</span> 'VAR_PATHINFO' => 's', <span style="color: #008000;">//</span><span style="color: #008000;"> 兼容模式PATHINFO获取变量例如 ?s=/module/action/id/1 后面的参数取决于URL_PATHINFO_DEPR</span><span style="color: #008080;"> 9</span> 'VAR_TEMPLATE' => 't', <span style="color: #008000;">//</span><span style="color: #008000;"> 默认模板切换变量</span><span style="color: #008080;">10</span> 'VAR_AUTO_STRING' => <span style="color: #0000ff;">false</span>, <span style="color: #008000;">//</span><span style="color: #008000;"> 输入变量是否自动强制转换为字符串 如果开启则数组变量需要手动传入变量修饰符获取变量</span>
PATHINFO模式
1 const URL_PATHINFO = 1; //PATHINFO模式 该模式是默认模式
URL: http://localhost/index.php/home/user/login/var/value/
PATHINFO地址的前三个参数分别表示模块/控制器/操作。
说白了就是把普通模式下的几个M C A 变量给省掉 使用斜杠来代替
好处:1.看上去很整齐 2.据说可以提高被搜索引擎抓住的几率哦!!!
当然是斜杠还是别的是可以设置的在 ThinkPHP\Conf\Convention.php 文件中可以进行设置
1 'URL_PATHINFO_DEPR' => '/', // PATHINFO模式下,各参数之间的分割符号
REWRITE模式
1 const URL_REWRITE = 2; //REWRITE模式
官方的原话 : REWRITE模式是在PATHINFO模式的基础上添加了重写规则的支持,可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则。
如何是这样,那么我觉得应该就是 浏览器地址给重写以后在按照PATHINFO模式进行解析路由
兼容模式
1 const URL_COMPAT = 3; // 兼容模式
URL http://localhost/?s=/home/user/login/var/value
看到这个地址 YII的人有木有感觉很熟悉
为什么是S开头呢?是因为配置文件的设置 在 ThinkPHP\Conf\Convention.php
1 'VAR_PATHINFO' => 's', // 兼容模式PATHINFO获取变量例如 ?s=/module/action/id/1 后面的参数取决于URL_PATHINFO_DEPR
修改模式方法
在配置文件 ThinkPHP\Conf\Convention.php
1 'URL_MODEL' => 1, // URL访问模式,可选参数0、1、2、3,代表以下四种模式: 2 // 0 (普通模式); 1 (PATHINFO 模式); 2 (REWRITE 模式); 3 (兼容模式) 默认为PATHINFO 模式
对于以上集中模式个人的小总结:
不管是那个 我们把URL中出了模块名称开始前都去掉,就是不同的几种取出模块、控制器、控制器其中的方法名。所以在不配置路由和不使用默认的情况下,我们都能看到这三个参数。
总结:
ThinkPHP\ThinkPHP.php文件中 最主要的目的还是定义好各种目录的变量方便以后的调用
如果你发现代码中有一个定义你不知道做什么,如果是_path结尾(关于目录的),就去ThinkPHP\ThinkPHP.php中找找,别的那么就去ThinkPHP\Conf\Convention.php下找找 基本都能找到
几个思考(个人在整理时候想到的):
1.定义IS_CGI ,IS_WIN,IS_CLI,MAGIC_QUOTES_GPC干嘛用
<span style="color: #008080;"> 1</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 系统信息</span><span style="color: #008080;"> 2</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">version_compare</span>(<span style="color: #ff00ff;">PHP_VERSION</span>,'5.4.0','<'<span style="color: #000000;">)) {</span><span style="color: #008080;"> 3</span> <span style="color: #008080;">ini_set</span>('magic_quotes_runtime',0<span style="color: #000000;">);</span><span style="color: #008080;"> 4</span> <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #008080;">get_magic_quotes_gpc</span>()? <span style="color: #0000ff;">true</span> : <span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;"> 5</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;"> 6</span> <span style="color: #008080;">define</span>('MAGIC_QUOTES_GPC',<span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">}</span><span style="color: #008080;"> 8</span> <span style="color: #008080;">define</span>('IS_CGI',(0 === <span style="color: #008080;">strpos</span>(PHP_SAPI,'cgi') || <span style="color: #0000ff;">false</span> !== <span style="color: #008080;">strpos</span>(PHP_SAPI,'fcgi')) ? 1 : 0<span style="color: #000000;"> );</span><span style="color: #008080;"> 9</span> <span style="color: #008080;">define</span>('IS_WIN',<span style="color: #008080;">strstr</span>(<span style="color: #ff00ff;">PHP_OS</span>, 'WIN') ? 1 : 0<span style="color: #000000;"> );</span><span style="color: #008080;">10</span> <span style="color: #008080;">define</span>('IS_CLI',PHP_SAPI=='cli'? 1 : 0);
2.为什么我们刚下载的架构不需要输入模块、控制器、方法名也能正常跳出页面。
好了,下一次我们就拿上小米加步枪杀进TP大门
1 // 应用初始化 2 Think\Think::start();

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

PHP在電子商務、內容管理系統和API開發中廣泛應用。 1)電子商務:用於購物車功能和支付處理。 2)內容管理系統:用於動態內容生成和用戶管理。 3)API開發:用於RESTfulAPI開發和API安全性。通過性能優化和最佳實踐,PHP應用的效率和可維護性得以提升。

PHP是一種廣泛應用於服務器端的腳本語言,特別適合web開發。 1.PHP可以嵌入HTML,處理HTTP請求和響應,支持多種數據庫。 2.PHP用於生成動態網頁內容,處理表單數據,訪問數據庫等,具有強大的社區支持和開源資源。 3.PHP是解釋型語言,執行過程包括詞法分析、語法分析、編譯和執行。 4.PHP可以與MySQL結合用於用戶註冊系統等高級應用。 5.調試PHP時,可使用error_reporting()和var_dump()等函數。 6.優化PHP代碼可通過緩存機制、優化數據庫查詢和使用內置函數。 7

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PHP仍然具有活力,其在現代編程領域中依然佔據重要地位。 1)PHP的簡單易學和強大社區支持使其在Web開發中廣泛應用;2)其靈活性和穩定性使其在處理Web表單、數據庫操作和文件處理等方面表現出色;3)PHP不斷進化和優化,適用於初學者和經驗豐富的開發者。

PHP適合web開發,特別是在快速開發和處理動態內容方面表現出色,但不擅長數據科學和企業級應用。與Python相比,PHP在web開發中更具優勢,但在數據科學領域不如Python;與Java相比,PHP在企業級應用中表現較差,但在web開發中更靈活;與JavaScript相比,PHP在後端開發中更簡潔,但在前端開發中不如JavaScript。

PHP和Python各有優劣,選擇取決於項目需求和個人偏好。 1.PHP適合快速開發和維護大型Web應用。 2.Python在數據科學和機器學習領域佔據主導地位。

PHP主要是過程式編程,但也支持面向對象編程(OOP);Python支持多種範式,包括OOP、函數式和過程式編程。 PHP適合web開發,Python適用於多種應用,如數據分析和機器學習。
