Re: [PHP-WIN] Include Question!

This is a discussion on Re: [PHP-WIN] Include Question! within the PHP General forums, part of the PHP Programming Forums category; Please include the list when replying, unless you're willing to pay my standard hourly rate. On 9 May 2008, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-09-2008
Stut
 
Posts: n/a
Default Re: [PHP-WIN] Include Question!

Please include the list when replying, unless you're willing to pay my
standard hourly rate.

On 9 May 2008, at 20:49, Matthew Gonzales wrote:

> Thanks for the responses. I think that I need to clarify.
>
> I am looking to use an include to minimize the amount of code on the
> page. So I wanted to use an include to call the code from another
> file. They are functions that query and update the databse and move
> uploaded files. Hope this make more sense.


That's fine, just be sure not to include the file more than once per
request or you'll get error messages regarding redeclaration of
functions. You can also use the _once variations of include or require
to get around this but bear in mind this causes a small performance hit.

-Stut

--
http://stut.net/

> Stut wrote:
>> On 9 May 2008, at 18:56, Bradley Stahl wrote:
>>> Your code would essentially be "inserted" in the place where your
>>> include
>>> statement is called. Let's say that your in 'page.php' you had the
>>> following code:
>>>
>>> echo "I AM IN PAGE.PHP!";
>>>
>>> and then in your script you have your code:
>>>
>>> if (some variable) {
>>> include('page.php');
>>> }
>>>
>>>
>>> This would essentially be giving you the code:
>>>
>>> if(some variable) {
>>> echo "I AM IN PAGE.PHP!";
>>> }
>>>
>>> I hope that this makes sense.. and this helps!

>>
>> That's not quite right and I think it's important to understand
>> exactly what PHP does here.
>>
>> PHP is executing a file and encounters file inclusion (include/
>> require(_once)). PHP will load and compile the included file.
>> During this stage it registers declarations in the global scope,
>> i.e. classes and functions. After that it executes the included
>> file in the same context from which it was included, so all local
>> vars visible inside your if block will be accessible. Once that
>> file's done PHP returns to executing the original file from the
>> statement after the include.
>>
>> Note that no code insertion takes place, it purely passes execution
>> to the included file. It's this sequence that prevents you from
>> defining a class across several files.
>>
>> Hope that makes it clearer.
>>
>> -Stut
>>

>
> --
> Matthew Gonzales
> IT Professional Specialist
> Enterprise Information Technology Services
> University of Georgia
> Email: matt323@uga.edu <mailto:matt323@uga.edu>
> Phone: (706)542-9538


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:39 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0