Is there a way that i can access $connect in all functions on class?
class topicClass {
function viewTopic() {
function grabId() {
global $connection;
}
function grabTopic(){
global $connection;
}
function grabReplies(){
global $connection;
}
}
}
Instead of writing it over and over?
Define it as a property of your class, like so:
class topicClass {
private $connection;
public function __construct() {
$this->connection = "myConnectionString";
}
function viewTopic() {
// you can then refer to $this->connection here
}
...
}
When you do:
var cls = new topicClass();
the construct() will be called and will assign the value to connection, and you can then refer to it in the other functions.
NOTE: In the example I gave, I used private. You may need to change that to public, depending on where you need to access it.