# Include/require into namespace

- Thread: https://externals.io/message/38988
- Original archive: https://news-web.php.net/php.internals/38988
- Started by Geoffrey Sneddon on 2008-07-15T19:55:28+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #38988 — Geoffrey Sneddon — 2008-07-15T19:55:28+00:00

URL: https://externals.io/message/38988#38988

Hi,

With the impending release of PHP 5.3 and the addition of namespaces  
into PHP, there becomes the issue of integrating libraries that are  
designed to still support PHP 4 (please, don't turn this into a  
discussion about whether they should or not: this _is_ a real issue)  
into something designed to use namespaces throughout. A simple  
solution would be to just include/require a file _into_ a namespace,  
which makes the default namespace in that file that namespace.

e.g. (inc. the case of defining a namespace in the included into a  
namespace file),

a.php:
<?php

require 'b.php' into Foo;
Foo::hi();
echo "\n";
Bar::magic();

?>

b.php:
<?php

function hi() {
	echo 'Hello, world!';
}

namespace Bar;

function magic() {
	echo 'Wow! This is in a namespace both here and there!';
}

?>

Expected output:
Hello, world!
Wow! This is in a namespace both here and there!


--
Geoffrey Sneddon
<http://gsnedders.com/
