Jump to content

[SOLVED] constants and private variables in a class


jordanwb

Recommended Posts

I'm making a MySQL class for easy database access. In the constructor I call mysql_connect and save the result in $connection which is an instance variable. Is it possible to make it private?

 

Also can I declare constants in a class and have them accessable like so:

 

class foo
{
define ("CONST", 7);


}

$foo = new foo;

print foo->CONST;

Is it possible to make what private? The $connection?

And yes you can put constants into your classes.

e.g.

 

class MySQL {

const MYCONSTANT = 7;
private $connection;

public function __construct(){
   $this->connection = mysql_connect(....etc....);
}

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.