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



Hi,

Use require_once instead of require to ensure the include is evaluated
only once per interpreter.

Regards,

John Peters

On Mar 29, 8:14 pm, Andrew Falanga <af300...@xxxxxxxxx> wrote:
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

  • 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 ... <?PHP ...
    (comp.lang.php)
  • 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: [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)
  • Re: [PHP] OOP, dynamic class extention
    ... On Thursday 30 October 2003 12:29 pm, Marek Kilimajer wrote: ... > php is not c, you can't use constants this way. ... >> other classes extend the base class, but PHP won't let me do what I have ... >> Any thoughts on ways to overcome this? ...
    (php.general)
  • Re: variable scope
    ... >> out what the scoping rules are for php. ... > Because the lack of typing variables are always in the function scope. ... I tend to declare them close to where they are going to be used ...
    (comp.lang.php)