OOP question
Posted: Fri Feb 11, 2011 8:21 am
When calling or invoking things, do they have to be methods only?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
John Cartwright wrote:What do you mean exactly?
You can invoke both functions and class methods. Although PHP does have an __invoke magic method that you can call a class like a function. See http://www.php.net/manual/en/language.o ... gic.invoke
Aside from the fact that this method needs to live inside a class, there is nothing wrong with that. In fact, I still have no idea what your talking about.phpCig wrote:It went like this
public function __construct(){
$this->connection;
}
Code: Select all
private function Connect()
{
try{
$this->connection = new mysqli(SERVER,DB_USER,USER_PWD,DB_NAME);
if(mysqli_connect_error()){
throw new Exception("Not connected to database");
} else {
return $this->connection;
}
}
catch (Exception $e){
echo ("Error: " . $e->getMessage());
}
}