I've been learning PHP as I go with a lot of trial and error and plenty or reading, too - and it's been working great, but I think I've missed something along the way.
It feels like I'm creating too many php files to make my site work...each one having a specific script or a single function on it, and I'm wondering if there's a way to put a lot of PHP functions/classes in one file and then call the specific scripts as needed from the php commands on other pages?
I use 'require' and 'include' here and there for saved snippets of code, but can I call specific snippets from a page with a lot of them on it? (sort of like the 'url_link#name.html' in HTML) or maybe like a "php stylesheet"...
Not sure I've been clear enough, but maybe some of you "PHP elders" know what I'm asking...
thanks in advance.
mc
too many php files
Moderator: General Moderators
There's nothing wrong with includes, unless (in my opinion) you have an index.php?page=this where 'page' is an included page... I feel that kind of coding is unnecessary.
As far as your question, you cannot do that, that I'm aware of.
You may want to rethink your reasoning behind your functions. If they are simple, why not just hardcode them into the script? If they are more complex, or repetitive and you use them a lot, then go ahead and throw them in an include file.
However, I do not suggest having a separate include file for each function. Have a page called 'functions' or something of the sort where you have all of your most used functions. There's definately nothing wrong with doing it either way. If the code is working, then it works, and the only thing more you could ask for is readability and good logic.
As far as your question, you cannot do that, that I'm aware of.
You may want to rethink your reasoning behind your functions. If they are simple, why not just hardcode them into the script? If they are more complex, or repetitive and you use them a lot, then go ahead and throw them in an include file.
However, I do not suggest having a separate include file for each function. Have a page called 'functions' or something of the sort where you have all of your most used functions. There's definately nothing wrong with doing it either way. If the code is working, then it works, and the only thing more you could ask for is readability and good logic.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
include the file, if you coded it right then it will not cost you any amount of time that you would ever notice. it is easier to manage 1 header page with like 6 inclues for whatnot then on ever subpage just include the header file which in turn includes the other pages and makes coding more easy to manage (at least for me)