I'm having this error, but it's not the case that the name is already used. In fact, it was working and continues to work correctly in other parts of the code.
The class Model
is an abstract class that connects to the database, the classes that need to connect to the bd extend the class Model
.
The error occurs when in the same file I call two methods of different classes, these two classes extend the class Model
.
//clase usuario
require_once($CLASES_DIR . 'usuario.class.php');
$usu = New usuario();
$usu->setCorreo($correo);
//metodo de la clase usuario
$id_cl = $usu->id();
//Llamo clase suscripcion
require_once($CLASES_DIR . 'suscripcion.class.php');
$sus = New suscripcion();
The only thing different from the rest of the code where it works is that in the same file I call two classes. How can i fix this?
EDIT: I add the files subscription.class.php and user.class.php
<?php
require('model.php');
class suscripcion extends Model{
private $id;
private $id_usu;
private $t_credito;
private $tipo_sus;
private $fecha_i;
private $fecha_f;
function __construct($id='',$id_usu='',$t_credito='',$tipo_sus='',$fecha_i='',$fecha_f=''){
//Cargo el constructor de la superclase
parent::__construct();
$this->id = $id;
$this->id_usu = $id_usu;
$this->t_credito = $t_credito;
$this->tipo_sus = $tipo_sus;
$this->fecha_i = $fecha_i;
$this->fecha_f = $fecha_f;
}
?php
require('model.php');
class usuario extends Model{
private $id;
private $nombre;
private $apellido;
private $correo;
private $contraseña;
private $tel;
private $suscripto; //boolean
private $t_credito;
private $estado;
function __construct($id='',$nombre='',$apellido='',$correo='',$contraseña='',
$tel='',$suscripto='',$t_credito='',$estado=''){
//Cargo el constructor de la superclase
parent::__construct();
$this->id=$id;
$this->nombre=$nombre;
$this->apellido=$apellido;
$this->correo=$correo;
$this->contraseña=$contraseña;
$this->tel=$tel;
$this->suscripto=$suscripto;
$this->t_credito=$t_credito;
$this->estado=$estado;
}
?php
abstract class Model{
protected $_db;
public function __construct(){
// Se conecta a la DB al instanciar la clase
$this->_db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ( $this->_db->connect_errno ){
echo "Fallo al conectar a MySQL: ". $this->_db->connect_error;
return;
}
$this->_db->set_charset(DB_CHARSET);
}
}