evaluation of if condition
| From: | Petersen, Moritz \(E-Mail 3\) | Date: | Thu, 28 Dec 2000 16:44:21 +0000 |
| Subject: | evaluation of if condition | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-42435@lists.php.net to get a copy of this message | ||
Hello,
i've got a general question about the if condition:
The problem is as follows.
I'm using a set of classes with my scripts. But instead of including all the
classes at the top of the script like
[... main script ...
include("class_a.php");
include("class_b.php");
instance_b = new class_b();
... main script ... ]
I am using the following construction of 'dynamic' class-loading:
[... main script ...
if (!$__CLASS_B__)
{
include("class_b.php");
}
instance_b = new class_b();
... main script ]
and in class_b.php there is the following construction:
[... class_b.php ...
$__CLASS_B__ = true;
if (!$__CLASS_A__)
{
include("class_a.php");
}
class class_b extends class_a
{
...
}
... class_b.php ...]
The big advandage is, that I only include the scripts that I really need and
them I include just once. Scripts, that I don't use I don't include!
The main problem is: I have to use a variable (like "$__CLASS_B__") in
another script. What, if the variable changes (for some reason). Then I have
to change all other scripts, too!
A possible solution would be like:
[... main script ...
$include("class_b.php");
$instance_b = new class_b();
... main script ...]
[... class_b.php ...
if (!$__CLASS_B__)
{
$__CLASS_B__ = true;
include("class_a.php");
class class_b extends class_a
{
...
}
}
... class_b.php ...]
That would be very cool.
I am sure, this would work, but I am uncertain, if this wouldn't make the
script very big - and slow!
For your opinions about that I would be very thankful.
Bye,
Moritz.