Re: default extension for includes?

From: Date: Tue, 23 Nov 2004 13:11:01 +0000
Subject: Re: default extension for includes?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-202720@lists.php.net to get a copy of this message
Justin French wrote:
On 23/11/2004, at 12:44 PM, Jake Press wrote:
Justin, 'Use the force luke' - or perhaps just write yourself a function to do this :)
Sadly, included files inside functions don't inherit the global namespace, so you have to do something ridiculous like extract($GLOBALS) inside the function: function includer($thing)
    {
    extract($GLOBALS);
    include($thing.".inc");
    }
The extract isn't too expensive, but it's definitely something I'd like to avoid if possible.
This would not work, extract creates a copy of the variables, changing them in $thing . '.inc' will have no efect outside of the file. You would have to loop $GLOBALS and assign by reference, while skipping superglobals.

« previous php.general (#202720) next »