__halt_compiler

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

__halt_compiler — 中断编译器的执行

说明 ¶

__halt_compiler(): void

中断编译器的执行。常用于在 PHP 脚本内嵌入数据,类似于安装文件。

可以通过常量 __COMPILER_HALT_OFFSET__ 获取数据开始字节所在的位置,且该常量仅被定义于使用了 __halt_compiler() 的文件。

参数 ¶

此函数没有参数。

返回值 ¶

没有返回值。

范例 ¶

示例 #1 __halt_compiler() 例子

<?php// open this file$fp = fopen(__FILE__, 'r');// seek file pointer to datafseek($fp, __COMPILER_HALT_OFFSET__);// and output itvar_dump(stream_get_contents($fp));// the end of the script execution__halt_compiler(); the installation data (eg. tar, gz, PHP, etc.)

注释 ¶

注意:

__halt_compiler() 仅能够在最外层作用域使用。

+add a note

User Contributed Notes 7 notes

up
down
26
-T- ¶
9 years ago
This function can be used in eval() -- it will halt the eval, but not the script eval"() was called in.
up
down
15
ravenswd at gmail dot com ¶
7 years ago
If "__halt_compiler();" appears in a file which is "include"d or "require"d, then the called-in file will be treated as if it physically cuts off at the "__halt_compiler();". In other words, "__halt_compiler();" only affects the physical file it's in, an outer file that pulls it in will continue to execute.
up
down
18
ravenswd at gmail dot com ¶
12 years ago
__halt_compiler is also useful for debugging. If you need to temporarily make a change that will introduce an error later on, use __halt_compiler to prevent syntax errors. For example:<?phpif ( $something ):  print 'something';endif;   // endif placed here for debugging purposes__halt_compiler();endif;   // original location of endif -- would produce syntax error if __halt_compiler was not there?>
up
down
1
alex at 1stleg dot com ¶
3 years ago
Please note that __HALT_COMPILER() must be uppercase if used from a pharstub: https://www.php.net/manual/en/phar.fileformat.stub.php
up
down
2
joey at gimo dot co dot uk ¶
8 years ago
I don't exactly know what PHP is doing internally but I don't understand the sanity behind how in token_get_all __halt_compiler is handled.This is actually valid there:__halt_compiler/**/ /**/ /**/ /**/ /** */();rawNormally it pops off just any three tokens so you can have even __halt_compiler***, __halt_compiler))), etc in token _get all.The weird thing is that is also skips T_OPEN_TAG but in the context __halt_compiler runs in this tag should not be posible. Instead it will pick up < and ? as operators and php as a T_STRING.It ignores the token at any point so this is also valid:__halt_compiler()/**/ /**/ /**/ /**/ /** */;rawWhen I test this with a php file rather than the tokeniser it works the same.I can only conclude that PHP/__halt_compiler is pretty weird.I think this is from attempting to weakly imitate the same syntax handling as in functions (I guess you can put comments/whitespace anywhere). I find it annoying and counter productive though.Even this is valid:__halt_compiler// comment\n();rawA general problem that compound matters is that tokenise wont check whether or not syntax is valid (tokens against each other). When running as PHP you must have ();.
up
down
1
Krzysiek ¶
8 years ago
Joey, you're wrong saying that __halt_compiler have strange behavior. This structure works exactly the same as any other build in structure like empty or isset (even similarly to functions; at least in tokenizer level).About T_OPEN_TAG - after one open tag is present you didn't expect other one in current php code section, so tokenizer try to handle this "thing" in other way and it's perfectly normal...
up
down
0
cwk32 at mail dot ustc dot edu dot cn ¶
8 years ago
if you find the value of __COMPILER_HALT_OFFSET__ is highly strange. Maybe...there are some complier optimization tools, like eAccelator(very old). When the program is pre-complied and cached, the __COMPILER_HALT_OFFSET__ will be 0 = =

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

热门产品

php编程基础教程.pptx|php编程培训,php,编程,基础,教程,pptx
php编程基础教程.pptx

历史上的今天:04月20日

ThinkPHP5快速入门

ThinkPHP5快速入门目 录零、序言一、基础二、URL和路由三、请求和响应四、数据库五、查询语言六、模型和关联 (1)模型定义 (2)基础操作 (3)读取器和修改器 (4)类型转换和自动完成 (5)查询范围 (6)输入和验证 (7)关联 (8)模型输出七、视图和模板八、调试和日志九、API开发十、命令行工具十一、扩展十二、杂项SessionCookie验证

ThinkPHP5快速入门基础

ThinkPHP5快速入门基础一、基础快速入门 ( 一 ) :基础本章介绍了 ThinkPHP5 .0 的安装及基本使用 ,并给出了一个最简单的示例带你了解如何开始开发 ,主要包 含 :简介官网下载 omposer安装和更新CGit下载和更新目录结构运行环境入口文件调试模式控制器视图读取数据总结在学习 ThinkPHP5.0 之前 ,如果你还不理解面向对象和命名空间的概念 ,建议首先去PHP手册恶

热门专题

天麻的功效与作用吃法|天麻的功效与作用,天麻的功效与作用吃法,天麻炖什么治头痛最好,天麻的功效与作用禁忌,天麻多少钱一斤,天麻的功效与作用吃法及禁忌,天麻怎么吃效果最好,天麻粉的功效与作用,天麻怎么吃
天麻的功效与作用吃法
卓越综合高中|卓越综合高中
卓越综合高中
一年制中专|中专学历,中专是什么学历,中专是什么,中专有什么专业,中专升大专,一年制中专
一年制中专
安徽中源管业有限公司|安徽中源管业有限公司,安徽中源管业有限公司介绍,安徽中源管业有限公司电话,安徽中源管业有限公司地址,安徽中源管业有限公司厂家,安徽中源管业有限公司电力管,安徽中源管业有限公司管材
安徽中源管业有限公司
云南巨榕教育投资集团有限公司|云南巨榕教育投资集团有限公司,巨榕教育集团,巨榕教育
云南巨榕教育投资集团有限公司
开放大学|开放大学报名,开放大学报考,开放大学,什么是开放大学,开放大学学历,开放大学学费,开放大学报名条件,开放大学报名时间,开放大学学历,开放大学专业
开放大学
小程序开发|微信小程序,小程序开发,小程序,小程序制作,微信小程序开发,小程序公司,小程序开发公司,分销,三级分销系统,分销系统
小程序开发
云南综合高中|云南综合高中
云南综合高中

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部