OOP question
Moderator: General Moderators
OOP question
When calling or invoking things, do they have to be methods only?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: OOP question
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
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
Re: OOP question
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
I made up a code where I called a variable instead this method, and it caused an error message when I tried to run the script
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: OOP question
Post your code.
Re: OOP question
It went like this
public function __construct(){
$this->connection;
}
public function __construct(){
$this->connection;
}
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: OOP question
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;
}
Post your entire (relevant) code.
Re: OOP question
Yup, this is in a class
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());
}
} - John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: OOP question
You still haven't given me the error or the problematic code. From the code you've posted, there are no errors.