[PHP4] accessing constants outside class body

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Is there a way to see the value of a constant that is defined outside of the  
class body from within the class?

I need to do something like this, but it isn't working:

// in one file I define these settings
define('_DBUSER_', 'me');
define('_DBPASS_', 'secret');
define('_DBHOST_', 'localhost:3306');
define('_DBNAME_', 'mydb');

// then include this file in the file with the class definition

class DBWrapper
    var $dbuser;
    var $dbpass;
    var $dbhost;
    var $dbname;

    function DBWrapper()
        $this->dbuser = _DBUSER_;
        $this->dbpass = _DBPASS_;
        $this->dbhost = _DBHOST_;
        $this->dbname = _DBNAME_;

    // ...

thank you,


Re: accessing constants outside class body


This example code have to be working. I allways use code constructions
like this.

--Are you sure that your .inc code begin with '<?php ' and ends '?>'.

--Another one error that can be here is the path to *.inc file. You can
don't see warnings by apache configuration ("php_value error_reporting
7" for example) but really that file not found and don't including. Try
to check path to that *.inc file.

Sorry for my inglish and best regards.

Re: accessing constants outside class body

Thanks, turns out I was doing something wrong - that code I posted DOES  


Site Timeline