![]() |
Clarification on INCLUDE()
Hello all --
A large portion of the PHP program I'm working on is repeated about 2000 times, but before it can be properly initialized at the start of each loop, about 50 variables (counters) have to be set back to 0. I just want to do this "tidily," if that is a word...:-/ Don't want to do this in a function because I'd have to set all the variables to a global state. Just wondering if I could do this by having the code (setting the variables to 0) in a separate PHP file and include() it at the top of every iteration of the loop...? Is that an acceptable interpretation of a proper use of include()? I've read the online php.net documentation several times, but I'm still a little unsure on this point. Thanks! Dave |
In short, yes.
|
Thanks for info on INCLUDE()...
Great! Thanks for your quick response.
So, a PHP file that is called repeatedly using INCLUDE() is the same as a subroutine or procedure. Good to know. 8-) Dave |
Basically though, if you initialize your variables properly your function calls of which get included would automatically set them to 0.
IE PHP Code:
|
Thanks very much for your response....
But wouldn't I have to declare the variables as "global" in order for the reset variables to be recognized by the calling script? Or, I may be totally missing what you are pointing out...:-/ Dave |
I'm not sure what he's up to there, but you only need to declare your variables global if you set them in the global scope (ie, outside a function, or inside a function that declares them global) and you want to use them inside of another function. ie
PHP Code:
-m |
Sorry, I missed the part about them being needed to be used globally.
Object Oriented Programming FTW! :) Once i started doing object oriented, I have sort-of lost sight of procedural. PHP Code:
|
when you use includes you MUST use relative paths in order for variables to work between pages.
|
Thanks CoryMatthews and drewbee for your responses. :-)
The OOP approach just looks to me (an amateur) like the opportunity to drive into a very dense fog -- in the middle of the night -- in a place I've never been before. Or going from LA to San Francisco, by way of New York. I know it is not that way, but that's the way it looks from down here.:-P Dave |
haha, yeah I know what you mean. The language itself isn't to hard to use within PHP... however understanding OOP concepts can take some time to grasp onto. But I tell you, once you get it, its a hole new world of programming. I use OOP far more then what I should, I think. I think its so much easier to maintain though!
|
oop isn't really harder than procedural. in fact, i think its easier, in alot of aspects. more organization. idk, just my opinion.
Instead of having to call/include the entire script repeatedly, using a class would only require 1 inclusion, and then you can infinatly call your functions throughout your site. Using something like what drewbee just posted, would be alot more efficent for what you are doing, than the route you are attempting. IMO helps save on unnessessary page calls, etc... not to mention if you take the time to write out a "framework" so-to-speak of your own, a system of functions, and methods that you use regularly. which would only leave minor additions/edits to your classes, and alows you to do more proceedural stuff. |
Yup. I agree Evulness. I have my own framework integrated with Smarty...
Everyone of my forms (the display or controller; not the html code but the part that tells which html templates to display) consists of about 10 lines of code. This completely handles whether people can access the page (permissions), session handling, and database management. gotta love oop! |
| All times are GMT. The time now is 11:21 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0