在翻看TP源码时发现一个C函数,我对其做了一些注释。
原文地址:http://chenlanlong8810.blog.163.com/blog/static/113899578201275103718201/
在翻看TP源码时发现一个C函数,我对其做了注释,函数定义如下:// 获取配置值<br>
function C($name=null, $value=null) {<br>
//此方法是一个变量库,static变量每次都会保存下来<br>
static $_config = array();<br>
// 无参数时获取所有<br>
if (empty($name))<br>
return $_config;<br>
// 优先执行设置获取或赋值<br>
if (is_string($name)) {<br>
if (!strpos($name, '.')) {<br>
$name = strtolower($name);<br>
if (is_null($value))<br>
//若$value为不空表明是变量注册,为空表明是变量查找<br>
return isset($_config[$name]) ? $_config[$name] : null;<br>
$_config[$name] = $value;<br>
return;<br>
}<br>
// 二维数组设置和获取支持<br>
$name = explode('.', $name);<br>
$name[0] = strtolower($name[0]);<br>
if (is_null($value))<br>
return isset($_config[$name[0]][$name[1]]) ? $_config[$name[0]][$name[1]] : null;<br>
$_config[$name[0]][$name[1]] = $value;<br>
return;<br>
}<br>
// 批量设置<br>
if (is_array($name))<br>
//若$name为数组,则返回所有的配置变量<br>
return $_config = array_merge($_config, array_change_key_case($name));<br>
return null; // 避免非法参数<br>
}
注意$_config变量前有static修饰,所以$_config在内存中存在于静态数据段,只要TP程序还在运行,其值将一直存在。C()函数有两种用法,若只传一个参数,表示查找常量。若传两个参数,表示常量注册。
还有一点需要说明的是include()的返回值是什么呢?
include()的返回值一般情况下要包含的文件存在则返回true,不存在则返回false。但是,当要包含的文件中有return的时候include()的返回值是所return的值而不是true OR false。
C.zip
( 665 B 下载:24 次 )
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!