<?php
class Mobil
{
var $warna;
var $merk;
var $harga;
function __construct()
{
$this->warna = "Biru";
$this->merk = "BMW";
$this->harga = "10000000";
}
function gantiWarna ($warnaBaru)
{
$this->warna = $warnaBaru;
}
function tampilWarna ()
{
echo "Warna mobilnya : " . $this->warna;
}
}
$a = new Mobil();
$b = new Mobil();
echo "Mobil pertama<br>";
$a->warna;
echo $a ;
?>
Setelah di-run, ada error di bagian $a->warna yang berbunyi "Catchable fatal error: Object of class Orang could not be converted to string ". Bukankah objek mengakses variabel sintaxnya seperti itu ?
0 jempol
bramanto
300
1167
·
8 tahun, 10 bulan yang lalu
·
0 jempol
Halo coder @FahmiIrmansyah, Untuk mengakses warna coder cukup menuliskan seperti ini : echo $a->warna;