Include/require into namespace

From: Date: Tue, 15 Jul 2008 19:55:28 +0000
Subject: Include/require into namespace
Groups: php.internals 
Request: Send a blank email to internals+get-38988@lists.php.net to get a copy of this message
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/>

« previous php.internals (#38988) next »