the include and require directives appear to cause the constructor of the specified file to run.
I expected to do this:
include 'myClass.php';
.
.
.
$myClass = new myClass();
but this actually causes 2 instantiations of myClass
to get what i want, i move the include statement to where the $myClass = new myClass statement is (and remove the $myClass statement)
its not like the C include, nor is it like a Java import.
no question, i guess, just seems odd to me.
comments welcome, though.
include / require runs constructor
Moderator: General Moderators
-
allelopath
- Forum Commoner
- Posts: 34
- Joined: Tue Mar 16, 2004 5:21 am
It should not (depending on the script that is). Can you display more code for us?
Can you verify that this alone, gives you 2 instances?:
If not, you need to look elsewhere. If so, check the myClass.php file for more information...
Can you verify that this alone, gives you 2 instances?:
Code: Select all
<?php
include 'myClass.php';
echo 'foo';
$myClass = new myClass();
?>-
allelopath
- Forum Commoner
- Posts: 34
- Joined: Tue Mar 16, 2004 5:21 am
-
allelopath
- Forum Commoner
- Posts: 34
- Joined: Tue Mar 16, 2004 5:21 am