Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:09:37+00:00 2026-06-18T10:09:37+00:00

Hello Fellow Stack Over Flow members, I hope you guys can help with me

  • 0

Hello Fellow Stack Over Flow members, I hope you guys can help with me something that I have been unable to figure out. I have been unable to write a class for the below code, I was hoping one of you php experts could help

$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 ();

Every time I attempt to write a class it either prints out blank or Web Storm is throwing an error about method not being declared in class.

code I used:

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;
}}

any code suggestions would greatly be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:09:38+00:00Added an answer on June 18, 2026 at 10:09 am

    that’s kind of a big mess! 🙂 You’re mixing setters/getters and direct access, and are using old school constructors. You can clean it up really quickly.

    class Property
    {
        public function __construct($name, $price, $address_1, $address_2, $city, $state, $zip) 
        {
                $this->name = $name;
                $this->price = $price;
                $this->address_primary = $address_1;
                $this->address_secondary = $address_2;
                $this->city = $city;
                $this->state = $state;
                $this->zip = $zip;
        }
    }
    

    If you set up your class like such with all your variables in the constructor, then you should be using it like:

    $obj = new Property(
        "Name of Something",
        500,
        "First Line",
        "Second Line",
        "City",
        "State",
        "90210"        
    );
    
    
    echo 'Name :: ', $obj->name, PHP_EOL;
    echo 'Price :: $', $obj->price, PHP_EOL;
    echo 'Address :: ', $obj->address_primary, ' ', $obj->address_secondary, PHP_EOL;
    echo 'City, State, Zip :: ', $obj->city, ', ', $obj->state, ' ', $obj->zip;
    

    Marked issues with your code were:

    You’re mixing members with functions. This kind of stuff in your constructor is major breakage:

    $this->setName = $price
    

    You’re also mixing substring access [] with -> and using getters on top ->getName(). Be consistent, and in this case, respect the semantic of public variables.

    Lastly, you had parameters in your constructor, but weren’t using it at all.

    Alternative would be to assign values to your constructor signature variables by default to make them optional.

    public function __construct($name = "", $price = 0, $address_1 = "", $address_2 = "", $city = "", $state = "", $zip = "" )
    

    And then use the public member access as you had:

    $obj = new Property();
    $obj->name = "Some Name"; 
    

    Good luck with your learning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello fellow python users, I bring forth a question that I have been wondering
Hello fellow programmers. I have a SQL Server 2005 query that is taking a
Hello fellow stakoverflowers, I'm having a problem with PHP/Apache. I have an application that
Fellow JQuery hackers, hello :-) Suppose you have the following code: $('.links').click(function(){ //Do something
Hello fellow programmers I have been searching the internet for a few days now
Hello fellow C++ programmers. I have, what I hope to be, a quick question
Hello fellow earthlings, I have an image as my background that I created in
Hello Fellow Computer People! Anyone willing to help will have my gratitude ;) Just
Hello fellow computer people :) I have a shell script that I will use
hello fellow java developers. I'm having a bit of an issue here. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.