I have a really huge form handler implemented as a single php class.

The handler takes some POST values and depending on their contents calls
some very big member functions.
Now I have to add new functionality and I fear that a 500K php script will
kill server response time.

Since I don't have the time needed for a reenginering my first thought was
to split this big class into about 10 files to be loaded "on demand".

This would be made possible since the members functions are easily grouped
in fairly independent groups each consisting of 3 - 10 functions.

There would be also a "nucleus": the core of the current class (some 10s
functions) that is used widely by others functions (i.e. for authentication
and form variables decryption) and works as a sort of underlying "API".

Unfortunately it is not possible to make those groups completely detached as
normal functions due to the sheer amount of code referencing to the base

If it was C / C++ code (my normal working languages) I'd have no problems,
but in PHP I don't know how to do it (and in a "clean way").

In my intention the implementation had to be something like this:

1) Start of the code (global scope) -> Done.
2) Retrieve the operation to be performed (actually available operations are
identified by constants) -> Done.
3) Call some sort of OperationToInclueFileNames($CurrentOperation) function.
    It returns an array of php file names.
    Each of these contains the definitions and code of the functions needed
to process $CurrentOperation (and only them). -> Easily Done.
4) Some how require_once() or include_once() (*_once because there is code
that includes others modules in deep levels) at strategic points in order to
effectively load the needed code.
And there is the problem: I can't figure out a working way of putting member
functions outside the main class declaration (I'm using PHP 4.1.1 and it
will NOT be upgraded).
In C++ish style, given the :: scope resolution operator it would be simply a
matter of defining them in another file, i.e.


Class Foo {
Member1() {

Member2() {


$CurrentOperation = GetCurrentOperation();
$FileList = OperationToInclueFileNames($CurrentOperation);
For each $FileList element as $FileName require_once($FileName);


Foo::Member1() {

Foo::Member1A() {

Foo::Member1B() {

File 2.php:

Foo::Member2() {

Foo::Member2A() {

... and so on with other PHP files containing the needed code.

In "real" PHP I don't know how to do it, instead.
Perhaps it might be made to work for functions outside classes, but for me
this way is not an option.
Has anyone ever been in a similar situation and has he / she found a working
(i.e. tested) solution?

Thanks in advance,
Dario Fumagalli

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to