Answer the question
In order to leave comments, you need to log in
Am I using OOP correctly?
# константы
const DS = DIRECTORY_SEPARATOR;
# установка текущей директории
chdir(__DIR__);
# инициализация автозагрузки
spl_autoload_register(function($classname) {
$filepath = 'class'.DS.str_replace('\\', DS, $classname).'.php';
return file_exists($filepath) ? include_once($filepath) : false;
});
private $db;
function __construct(DB $db) {
# установка класса БД
$this->db = $db;
}
const LOCALES_TABLE = 'com_locales';
class Locale {
private $localestable = LOCALES_TABLE;
# ...
}
const ABS_TABLES = serialize([
'com_abs_str',
'com_abs_int'
]);
class ABS_Tables {
private $tables;
function __construct() {
$tables = &$this->tables;
$tables = unserialize(ABS_TABLES);
}
# ...
}
$this->
when called. How correct is this?function GetLanguageByID($langid) {
# линки
$db = &$this->db;
$langstable = &$this->langstable;
# ...
}
private function CheckArgs(array $inputs) {
foreach ($inputs as $input)
if ($input === [] || $input === '' || $input === null)
return false;
return true;
}
function InsertValues($table, array $keys, array $values_arr) {
# проверка всех аргументов
if (!$this->CheckArgs(func_get_args()))
return;
# ...
}
function SelectValues($table, array $wherekeys = [], array $wherevalues = []) {
# проверка определенных аргументов
if (!$this->CheckArgs([$table]))
return;
# ...
}
Answer the question
In order to leave comments, you need to log in
All classes are organized into folders according to namespaces (if used) in the class folder. Loaded by autoloaderThe idea is good, but the execution is terrible.
Constants are defined outside of classes.In no case. Exclusively within classes.
In each method, the variables used are linked - I just got tired of constantly writing $this-> when calling. How correct is this?Forget about & for a year.
And to check the correctness of the input, I use this functionNot necessary. Just get familiar with the types.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question