Connecting Tech Pros Worldwide Help | Site Map

[PHP4] accessing constants outside class body

  #1  
Old December 21st, 2005, 11:35 AM
somaboy mx
Guest
 
Posts: n/a
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
include('settings.inc');

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,


..soma


  #2  
Old December 21st, 2005, 01:45 PM
Alexius
Guest
 
Posts: n/a

re: [PHP4] accessing constants outside class body


Hi.

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.

  #3  
Old December 22nd, 2005, 02:25 PM
somaboy mx
Guest
 
Posts: n/a

re: [PHP4] accessing constants outside class body


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

..s


Closed Thread