Salve a tutti,
ho notato che l'istanziazione di una classe (sebbene ripetuta tantissime volte) rallenta enormemente il codice, di circa 20 secondi.
Questo il codice dell'istanziazione :
codice:
foreach ($subsubsql as $subsubrow) {
$m_a = new ProspectMatrixAnswer($subsubrow["Id_Colonna"], $subsubrow["Id_Riga"], $subsubrow["Id_Risposta"], $subsubrow["Text"], $subrow["Extra_Text"]);
}
Questo il codice della classe:
codice:
class ProspectMatrixAnswer
{
private $id_risposta;
private $enabled = true;
private $text;
private $id; //id della colonna della matrice
private $row; //id della riga della matrice
private $is_file;
private $file;
private $extra_text;
function __construct($idA, $rowA, $id_rispostaA = -1, $textA = "", $extra_textA = "") {
$this->id = $idA;
$this->row = $rowA;
//$this->id_domanda = $id_domandaA;
//$this->codice_domanda = $codice_domandaA;
$this->id_risposta = $id_rispostaA;
$this->text = $textA;
$this->extra_text = $extra_textA;
}
function getId() { return $this->id; }
function getRow() { return $this->row; }
function getAnswer() { return $this->id_risposta; }
function getText() { return $this->text; }
function getExtraText() { return $this->extra_text; }
function getId_Domanda() { return $this->id_domanda; }
function getCodice_Domanda() { return $this->codice_domanda; }
function getEnabled() { return $this->enabled; }
function setEnabled($enabledA) { $this->enabled = (bool)$enabledA; }
function setIs_File($is) { $this->is_file = $is; }
function getFile() { return $this->file; }
function AddFile($files = array()) {
$this->is_file = true;
$this->file = new ProspectAnswerFile($files);
}
}
Se sostituisco l'istanziazione di questa classe con una classe vuota, il codice non subisce rallentamenti (con lo stesso numero di cicli).
Come mai questa classe mi rallenta così tanto? Non faccio altro che chiamare il suo costruttore.
Qualche aiuto pls.
Grazie