0
I have the class below:
<?php
namespace CONSTANTES;
class Constantes {
private $livre = true;
private $util;
private $site = array (
"dominio" => "crud.com.br",
"www" => "www.crud.com.br",
"http" => "http://www.crud.com.br",
"tituloSite" => "CRUD SITE",
"tituloAdmin" => "CRUD Administração",
"tituloLoja" => "CRUD LOJA",
"descricao" => "???",
"keywords" => "???",
"fundacao" => "???",
"ano" => "2018",
"proprietario" => "???",
"proprietarioDcto" => "???"
);
private $siteEndereco = array (
"rua" => "???",
"numero" => "???",
"complemento" => "???",
"bairro" => "???",
"cidade" => "???",
"estado" => "???",
"cep" => "???"
);
private $siteEnderecoCompleto;
private $siteTelefones = array (
"ddd" => "???",
"tel" => "???",
"cel" => "???"
);
private $siteRedesSocias = array (
"facebook" => "http://www.facbook.com/crud",
"instagram" => "http://www.instagram.com/crud",
"whatsapp" => "???"
);
private $imgDir = "_img";
private $charset = "UTF-8";
public function __construct($_util) {
if($this->livre == false) {
header("Location: ".$_SERVER["SERVER_PATH"]."/manutencao.php");
exit;
}
$this->util = $_util;
$this->siteEnderecoCompleto =
$this->siteEndereco["rua"]. ", ";
$this->siteEndereco["numero"]. ", ";
$this->siteEndereco["complemento"]. ", ";
$this->siteEndereco["bairro"]. ", ";
$this->siteEndereco["cidade"]. ", ";
$this->siteEndereco["estado"]. ", ";
$this->util->formataCep($this->siteEndereco["cep"]). ", ";
}
public function getLivre() {
return $this->livre;
}
public function getSite() {
return $this->site;
}
public function getSiteEndereco() {
return $this->siteEndereco;
}
public function getSiteEnderecoCompleto() {
return $this->getSiteEnderecoCompleto();
}
public function getSiteTelefones() {
return $this->siteTelefones;
}
public function getSiteRedesSociais() {
return $this->siteRedesSocias;
}
public function getImagemDir() {
return $this->imgDir;
}
public function getCharset() {
return $this->charset;
}
}
?>
As it is a class of properties that are immutable via code. That is, they are constants. I would add static
in them. In the form below:
<?php
namespace CONSTANTES;
class Constantes {
static private $livre = true;
static private $util;
...
But this practice changes the value of $livre
for false
;
How can I do that?
I also tried to:
static private final $livre = true;
It’s the same!
Use
static
is changing$livre
to false? I think the problem may be that calls you have to$this->livre
must becomeself::$livre
– Leite
worked. But what if I add final? What’s the difference? Type Static final private $var = "";
– Carlos Rocha