Re: Extending 'include' behavior in a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jochem Maas wrote:
short of playing around with the global keyword
(which won't work when you call includeIt() from
another function)) your pretty much stuck.

basically imho you need to rethink what it is your trying to do.

function have their own scope for a reason; maybe consider using
an array argument like so:

function incIt($file, $args = array())
{
	extract((array)$args);
	include $file; // don't forget some error checking
}

function includeIt($file, $args = array())
{
	// bla
	incIt($file, $args);
	// more bla
}

I broke it down into 2 functions to avoid local variables
being overridden in includeIt() [by the call to extract].

In addition to your solution, it is needed to transfer the variables by reference.

Your solution is good when you know what variables you want to transfer ahead, and then make a list of them. But if I want to transfer all the variables in the current environment scope?

-thanks, Eli.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux