-2
I am trying to get the error in a return from Curl
ini_set("display_errors",true);
ini_set("display_startup_erros",1);
error_reporting(E_ALL && E_NOTICE);
error_reporting( E_ALL | E_STRICT ); // PHP 5.3
error_reporting( E_ALL ); // Todas as outras versões
class consultaCep {
private $phpUtil;
private $erro = "";
public function __construct($_phpUtil) {
$this->phpUtil = $_phpUtil;
}
function consultarCepViaCep ($_cep) {
$_cep = $this->phpUtil->limpaCaracters($_cep);
$urliaCep = sprintf('http://viacep.com.br/ws/%s/json/ ', $_cep);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urliaCep);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
$data = json_decode($data);
if(isset($data->erro)) {
$this->erro = $data->erro;
} else {
return $data;
}
}
public function getErro () {
return $this->erro;
}
}
When I do:
require_once "_controlls/_util/PhpUtil.php";
$phpUtil = new PhpUtil();
$_POST["cep"] = "11111111";
$consultaCep = new consultaCep($phpUtil);
$consultarCep = $consultaCep->consultarCepViaCep($_POST["cep"]);
if($consultaCep->getErro() != "") {
print "Erro: ".$consultaCep->getErro();
} else {
print "<pre>";
print_r($consultarCep);
print "</pre>";
}
When it is correct, the return comes normal.
But when there is invalid zip error gives type 1 error
Ma when the error is of incomplete zip code does not give error and does not complete the data
curl_init
is a kind of exception? thecatch
should capture a specific count passes straight into the block.– rray
in the case of which the output? curl_exec? I have tendered, did not give!
– Carlos Rocha