jordanwb Posted November 15, 2007 Share Posted November 15, 2007 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; Link to comment https://forums.phpfreaks.com/topic/77468-solved-constants-and-private-variables-in-a-class/ Share on other sites More sharing options...
aschk Posted November 15, 2007 Share Posted November 15, 2007 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....); } } Link to comment https://forums.phpfreaks.com/topic/77468-solved-constants-and-private-variables-in-a-class/#findComment-392171 Share on other sites More sharing options...
jordanwb Posted November 15, 2007 Author Share Posted November 15, 2007 Thanks. Link to comment https://forums.phpfreaks.com/topic/77468-solved-constants-and-private-variables-in-a-class/#findComment-392194 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.