Re: Calling a file as a function
| From: | Jesper Juhl | Date: | Wed, 30 Aug 2000 11:40:09 +0000 |
| Subject: | Re: Calling a file as a function | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-31225@lists.php.net to get a copy of this message | ||
Thank you very much!
You are correct, doing
$a = 'Hello world';
$b = 2;
include( 'foo.php' );
produce exactely the results I'm after :-) I see now that adding code to
php to be able to call the file as a function would just be bloat.
Best regards,
Jesper Juhl
juhl@eisenstein.dk
>>>>>>>>>>>>>>>>>> Oprindelig meddelelse
>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<
Den 8/30/00, 6:05:21 AM, skrev php4@developersdesk.com til emnet Re:
[PHP-DEV] Calling a file as a function:
> 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