php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66077 Cannot use __HALT_COMPILER(); with require() in namespace.
Submitted: 2013-11-11 03:23 UTC Modified: 2013-11-11 16:28 UTC
From: kevin at herrera dot io Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.5.5 OS: Ubuntu 12.04 LTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kevin at herrera dot io
New email:
PHP Version: OS:

 

 [2013-11-11 03:23 UTC] kevin at herrera dot io
Description:
------------
If I require() a file within "namespace {}", I cannot call __HALT_COMPILER(); at the end of the script. Instead, I receive a fatal error.

Test script:
---------------
https://gist.github.com/kherge/7407259

Expected result:
----------------
Hello, world!

Actual result:
--------------
PHP Fatal error:  No code may exist outside of namespace {} in /home/kherrera/Testing/b.php on line 3
PHP Stack trace:
PHP   1. {main}() /home/kherrera/Testing/a.php:0

Fatal error: No code may exist outside of namespace {} in /home/kherrera/Testing/b.php on line 3

Call Stack:
    0.0001     235816   1. {main}() /home/kherrera/Testing/a.php:0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-11 06:10 UTC] phpmpan at mpan dot pl
"__halt_compiler() can only be used from the outermost scope."

http://php.net/manual/function.halt-compiler.php
 [2013-11-11 06:12 UTC] kevin at herrera dot io
The example demonstrates that this is not true in all cases.
 [2013-11-11 16:28 UTC] bwoebi@php.net
-Status: Open +Status: Not a bug
 [2013-11-11 16:28 UTC] bwoebi@php.net
There are two documented things: No code outside of a namespace with brackets and __halt_compiler only in the outermost scope.

So you simply can't use a __halt_compiler token in your code when you use namespaces with brackets.
 [2013-11-11 21:22 UTC] kevin at herrera dot io
The behavior is not consistent, which is what confused me.

I added "c.php", which shows "namespace {}" and "__halt_compiler" being used successfully together.

https://gist.github.com/kherge/7407259#file-c-php
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 15:00:01 2026 UTC