View Full Version : Where to place objects/functions

06-22-2006, 12:28 AM
I have some core functions, say object.php and functions.php which are useful for a lot small php programs I've made.

Should I place that code in for instance a directory called "core" and let all the other programs use it like this:
/program1 (calling core functions)
/program2 (calling core functions)
... and so on

Or should I copy the core functions into each and every other program directory, like this:
... and so on

Main question: If many useres try to access a php-file at the same time, is that a problem, or is the prosess forked (or something like that)?

Regards and thanks for some opinions!

06-22-2006, 12:44 AM
keeping them in one place is preferable, so that if you discover, for example, that your generic file-opening script has a security-flaw in it, you only need to worry about a single fix- likewise if you decide there's a way to optimise a function.
The downside, though, is that if you find you need to make a change to one of these functions, to make it more generic and suitable for a new task for example, you'll have to either ensure the interface remains constant (so that things that are calling the 'old' version still work) or make changes to existing code.
Also, if you do need to make changes, you better be certain that they're not going to break anything if you've got multiple things depending on them.
One option would be to use source-control, subversion for example, and have a single copy of the code that changes get made to, and then the versions inside the applications are checkouts of the repository.
This would mean that you can make the changes in a single place and test by checking out to one of your applications. If you see there are problems, you can revert back to the 'good' copy straight away, otherwise carry on the roll-out to everything else.

Multiple reads on a single file won't cause you problems until you get very high load.