View Full Version : [PHP] Cosa significa in PHP questa scritta?
$object->method()->testo();
$object->method()->testo;
Ovvero quell'"->testo() e ->testo cos'è? E che relazione ha con il method?
E' percaso il valore ritornato dal method?
tomminno
05-10-2009, 08:57
$object->method()->testo();
$object->method()->testo;
Ovvero quell'"->testo() e ->testo cos'è? E che relazione ha con il method?
E' percaso il valore ritornato dal method?
Così a occhio significa che method() restituisce un oggetto che ha un metodo pubblico testo() e una variabile pubblica testo.
mi fate un esempio per scrivere questi due metodi
Ho provato così, ma non funge
function GetInfo($id_reduction){
$query = $this->db->get_where('reductions', array('id_reduction' => $id_reduction));
$this->reduction = $query->row();
return $this->reduction
}
function GetPrice(){
return $this->reduction->price;
}
tomminno
17-11-2009, 00:56
Dovresti spiegare meglio cosa non funziona.
Così ad occhio stai usando CodeIgniter, sicuro di avere configurato tutto a dovere?
si, codeigniter lo uso normalmente.
tomminno
17-11-2009, 15:20
si, codeigniter lo uso normalmente.
Non hai risposto alla domanda principale: cosa non funziona?
Che errore ottieni?
che l'oggetto non è stato definito
tomminno
17-11-2009, 17:09
che l'oggetto non è stato definito
Quale oggetto?
Dov'è che ottieni l'errore?
Dovresti essere un pò più specifico nel riportare gli errori, altrimenti è impossibile aiutarti
echo $this->GetInfo($id)->GetPrice();
Fatal error: Call to undefined method stdClass::GetPrice()
tomminno
18-11-2009, 00:05
echo $this->GetInfo($id)->GetPrice();
Fatal error: Call to undefined method stdClass::GetPrice()
In base al poco codice che hai postato GetInfo ritorna $this->reduction il quale non ha il metodo GetPrice(), da qui l'errore.
Eventualmente dovresti usare:
echo $this->GetInfo($id)->price;
Ma mi sembra tutto molto confusionario.
vBulletin® v3.6.4, Copyright ©2000-2026, Jelsoft Enterprises Ltd.