I have a class called cliente
class cliente {
private $id;
private $nome;
function getId() {
return $this->id;
}
function getNome() {
return $this->nome;
}
function setId($id) {
$this->id = $id;
}
function setNome($nome) {
$this->nome = $nome;
}
}
And two other classes called selecionaCliente
and insereCliente
these two extend the cliente
class:
<?php
require_once 'cliente.php';
class insereCliente extends cliente{
private $pdo;
function __construct() {
require_once 'conbdd.php';
$db = new conbdd;
$this->pdo = $db->conectar();
}
function selId(){
try{
$sel=$this->pdo->prepare("SELECT name FROM clientes WHERE
id=:id");
$sel->bindValue(":id", $this->getId());
$sel->execute();
$temp=$sel->fetch();
$this->setNome($temp['nome']);
return TRUE;
} catch (PDOException $ex){
echo $ex->getMessage();
return FALSE;
}
}
<?php
require_once 'cliente.php';
class selecionaCliente extends cliente{
private $pdo;
function __construct() {
require_once 'conbdd.php';
$db = new conbdd;
$this->pdo = $db->conectar();
}
function insNome(){
try {
$ins= $this->pdo->prepare("UPDATE clientes SET nome=:nome WHERE
id=:id");
$ins->bindValue(":id", $this->getId());
$ins->bindValue(":nome", $this->getNome());
$ins->execute();
return TRUE;
} catch (PDOException $ex) {
echo $ex->getMessage();
return FALSE;
}
}
}
I want to validate and store client data within the cliente
class through the class that will use the information
If I instantiate the two classes selecionaCliente
and insereCliente
and set an information in selecionaCliente
will I be able to retrieve this information through the instance of class insereCliente
, or does each instance create a different client? If so, how could I make all classes use the same instance of cliente
?