Answer the question
In order to leave comments, you need to log in
OOP. whether to store data in an object?
I'm sorry for the probably stupid question, but it's hard to formulate it, so I don't even know how to google this topic. Prompt to the beginner as more correctly concerning OOP to store the data. It's hard to explain so far, so here are two examples:
class Class{
function FUNC(){
// код для получения DATA
return Data;
}
}
obj = new Class();
d = obj->FUNC();
class Class{
private DATA
function FUNC(){
if( this->DATA ){
return this->DATA;
} else {
// код для получения DATA;
this->DATA = DATA;
return DATA;
}
}
}
obj = new Class();
d = obj->FUNC();
Answer the question
In order to leave comments, you need to log in
Not both.
class Class {
private $data;
public function __construct($data) {
$this->data = $data;
}
public function data() {
return $this->data;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question