Re: Calling a file as a function

From: Date: Wed, 30 Aug 2000 04:05:21 +0000
Subject: Re: Calling a file as a function
Groups: php.dev 
Request: Send a blank email to php-dev+get-31214@lists.php.net to get a copy of this message
Addressed to: Jesper Juhl <juhl@eisenstein.dk> php-dev@lists.php.net ** Reply to note from Jesper Juhl <juhl@eisenstein.dk> Wed, 30 Aug 2000 09:19:00 GMT > > This may seem like a silly thing, but I think it would be nice to be > able to call a file as if it was a function. I don't think it is needed, as you can already do most anything you want already. > > Lets say I have a file foo.php that I include as a footer in many of > my documents. If I would like this file to do some conditional stuff > based on what file includes it, that would be difficult to do since I > cannot pass variables with include(). But if I could call the file > as if it were a function, and could pass a variable to it like > > foo.php( a = "Hello world", b = 2); > > In foo.php two global variables ($a and $b) should then be available > with the values "Hello world" and 2. If you do this: $a = 'Hello world'; $b = 2; include( 'foo.php' ); $a and $b have the expected values anywhere inside foo.php that is NOT in a function(); If you are inside a function() definition you will need to use a global statement to make the values visible, just like if you were not in an include. > Are there any plans to do a thing like this (or is there some obvious > way to do the above that I have missed?). > You can also get to all of the variables listed in phpinfo() from within the included file, so you might be able to use one of those to determine where you are being called from. Rick Widmer Internet Marketing Specialists http://www.developersdesk.com

« previous php.dev (#31214) next »