你好 Stack Over Flow 成员,我希望你们能帮助我一些我无法弄清楚的事情。我一直无法为下面的代码编写一个类,我希望你们中的一位 php 专家能提供帮助
$obj = new ClassName ();
$obj->setName ('Name of Something');
$obj->price = 500.00;
$obj ['address_primary'] = 'First Line of Address';
$obj->address_secondary = 'Second Line of Address';
$obj->city = 'the city';
$obj->state = 'ST';
$obj->setZip (12345);
echo 'Name :: ', $obj->name, PHP_EOL;
echo 'Price :: $', $obj ['price'], PHP_EOL;
echo 'Address :: ', $obj->address_primary, ' ', $obj->getAddressSecondary (), PHP_EOL;
echo 'City, State, Zip :: ', $obj->city, ', ', $obj ['state'], ' ', $obj->getZip ();
每次我尝试编写一个类时,它要么打印出空白,要么 Web Storm 抛出一个关于方法未在类中声明的错误。
我使用的代码:
var $name; // House Name
var $price; // Price of House
var $address_1; // Address 1
var $address_2; // Address 2
var $city; // City
var $state; // state
var $zip; // zip
// Class Constructor
function Property($name, $price, $address_1, $address_2, $city, $state, $zip) {
$this->setName = $name;
$this->price = $price;
$this->address_primary = $address_1;
$this->address_secondary = $address_2;
$this->city = $city;
$this->state = $state;
$this->zip = $zip;
}
// Getter/Setter functions
function get_name() {
return $this->name;
}
function set_name($newname) {
$this->name = $newname;
}
function get_price() {
return $this->price;
}
function set_price($newprice) {
$this->price = $newprice;
}
function get_address_1() {
return $this->address_primary;
}
function set_address_1($newaddress_1) {
$this->address_primary = $newaddress_1;
}
function get_address_2() {
return $this->address_secondary;
}
function set_address_2($newaddress_2) {
$this->address_secondary = $newaddress_2;
}
function get_city() {
return $this->city;
}
function set_city($newcity) {
$this->city = $newcity;
}
function get_state() {
return $this->state;
}
function set_state($newstate) {
$this->state = $newstate;
}
function get_zip() {
return $this->setZip;
}
function set_zip($newzip) {
$this->setZip = $newzip;
}}
任何代码建议将不胜感激!