mercredi 22 juin 2016

Can I include classes like that, and use it with MVC?

So I was just wondering if this is a proper way to work with classes and extending them like that, and if is it a good way to work with them and MVC.

First file:

class Main {
public function write($var) {
    echo $var;
}
public function loadClass($var) {
    include($var);
}
}

Second file:

class MainExtended extends Main { 
public function write2($var) {
    echo $var; 
} 
}

And the commands:

$var = new Main();
$var->write("kekeke<br>");
$var->loadClass("var.php");
$var2 = new MainExtended();
$var2->write2("kekek<br>");
$var2->write("lkke");

They work and print:

kekeke
kekek
lkke

The question is if it is good or bad to work like that?

Aucun commentaire:

Enregistrer un commentaire