I have a special page that I'm writing that uses a common php file that I used in an extension I previously developed. Since I want these two to be independent, I have the common file in each of the extension directories.
I use require_once() to load the file (it's not a class but a few functions) but, since the two files are in two different directories, the require_once() doesn't detect that it's already loaded (it checks both path and file to determine a match). Hence, I get a redefinition error.
Since it's not a class, I don't use $wgAutoloadClasses. I'm avoiding making the functions part of an otherwise empty class, since I don't want to use the class::function() syntax. I could put them in a class file that contains an empty class and instantiate it just to load the file, but I was wondering if there is another, commonly accepted way to avoid this problem?
Mike
On 20/04/07, Michael Daly mikedaly@magma.ca wrote:
Since it's not a class, I don't use $wgAutoloadClasses. I'm avoiding making the functions part of an otherwise empty class, since I don't want to use the class::function() syntax. I could put them in a class file that contains an empty class and instantiate it just to load the file, but I was wondering if there is another, commonly accepted way to avoid this problem?
The classic approach to headers and includes, perhaps?
if( !defined( 'MYINCLUDE' ) ) { // all the include code define( 'MYINCLUDE', true ); }
Rob Church
Rob Church wrote:
The classic approach to headers and includes, perhaps?
if( !defined( 'MYINCLUDE' ) ) { // all the include code define( 'MYINCLUDE', true ); }
Aah, like C/C++ - shows I'm a PHP newbie.
Thanks!
Mike
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Rob Church wrote:
On 20/04/07, Michael Daly wrote:
Since it's not a class, I don't use $wgAutoloadClasses. I'm avoiding making the functions part of an otherwise empty class, since I don't want to use the class::function() syntax. I could put them in a class file that contains an empty class and instantiate it just to load the file, but I was wondering if there is another, commonly accepted way to avoid this problem?
The classic approach to headers and includes, perhaps?
if( !defined( 'MYINCLUDE' ) ) { // all the include code define( 'MYINCLUDE', true ); }
You may also consider using function_exists() etc.
- -- brion vibber (brion @ wikimedia.org)
mediawiki-l@lists.wikimedia.org