What mechanism may be used in PHP that will act as #define and #ifndef



The question is I have a base class in file1 and files file2 and file3
both contain classes that derive from the base class in file1. I'm
running in to a redefinition problem when I'm loading the files. What
I'd like is something like this:

file1:
<?php
// defining stuff
?>

file2:
<?PHP
require("path/to/file1");

// doing important stuff
?>

file3:
<?php
require("path/to/file1");
//doing important stuff
?>

Then in the "main" files I have:
main:
<?php
require("path/to/file2");
require("path/to/file3");
// do important stuff
?>

Now, I'm getting the redefinition problem here. In C or C++, I'd do:

#ifndef SOMETHING
#define SOMETHING
// code here
#endif

Is there something that would do this php? I haven't actually tried
wrapping the base class definition in a conditional because I thought
I remember reading that PHP uses the same scope rules as C and C++.
If I define something inside the scope of a conditional, that
something goes out of existence when that scope moves out. Is this
true, or would a conditional be the answer?

Thanks,
Andy
.



Relevant Pages

  • Re: Opinions / Votes Needed
    ... need added in to PHP 6, ... If you really *need* to used a staticly typed language then don't use PHP, ... A base class type which all objects automagically extend, ... Thoughts, Opinions, Votes? ...
    (php.general)
  • OOP, dynamic class extention
    ... I want to be able to set a base class in a settings file, ... but PHP won't let me do what I have tried. ... Fatal error: Class cepweb: Cannot inherit from undefined class my_base_class ...
    (php.general)
  • Re: "include" a .m file into another .m file
    ... % main script body ... % read lines in file 'file1' and execute them as matlab commands. ... Like php scripts that you can import anywhere in your php ...
    (comp.soft-sys.matlab)
  • Re: require_once() question for PHP programmers with C or C++ background
    ... PHP) works. ... files (FILE 1 and FILE2): ... file1 includes constants.php (via ... your constants are defined within a conditional block. ...
    (comp.lang.php)
  • Re: [PHP] OOP, dynamic class extention
    ... Jackson Miller wrote: ... > I want to be able to set a base class in a settings file, ... > classes extend the base class, but PHP won't let me do what I have tried. ...
    (php.general)