I'm 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 is normal.
But when there is an invalid zip error it gives type 1 error
Ma when the error is of incomplete cep does not give error or complete the data