Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 21st, 2005, 11:35 AM
somaboy mx
Guest
 
Posts: n/a
Default [PHP4] accessing constants outside class body

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
Default Re: 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
Default Re: accessing constants outside class body

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

..s


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles