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 5970867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:26:11+00:00 2026-05-22T20:26:11+00:00

I was previously mostly scripting in PHP and now considering getting more serious about

  • 0

I was previously mostly scripting in PHP and now considering getting “more serious” about it 🙂

I am working on a hiking website, and I needed to put some values into an object that I then try to pass back to the calling code.

I tried doing this:

$trailhead = new Object ();

But the system sort of barfed at me.

Then I didn’t declare the object at all, and started using it like this:

$trailhead->trailhead_name = $row['trailhead_name'];
$trailhead->park_id = $row['park_id'];

That seemed to work reasonably ok. But there are at least 3 problems with this:

  1. Since that code gets executed when getting things from the database, what do I do in case there is more than one row?

  2. When I passed the $trailhead back to the calling code, the variables were empty

  3. I actually am maybe better off making a real object for Trailhead like this:

    class Trailhead
    {
        private $trailhead_name;
        private $park_id;
        private $trailhead_id;
    
        public function __construct()
        {
            $this->trailhead_name    =    NULL; 
            $this->park_id    =    NULL; 
            $this->trailhead_id    =    NULL;     
        }
    }
    

What do people generally do in these situations and where am I going wrong in my approach? I know its more than one place 🙂

  • 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-05-22T20:26:12+00:00Added an answer on May 22, 2026 at 8:26 pm
    1. $trailheads[] = $trailhead;
    2. I’d do a print_r() of $trailhead to check that it’s what you expect it to be. The default object type in PHP is going to be stdClass.
    3. Yes, that’s going to be better, as it’ll allow your Trailhead objects to have functions. The way you’re currently doing it is basically taking advantage of none of PHP’s object functionality – it’s essentially an array with slightly different syntax.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Previously I've asked about inserting a column into a dataset . I now have
I've mostly worked in MVC1. I'm now working with some MVC2 code. I have
I previously asked how to do this in Groovy. However, now I'm rewriting my
I previously asked about what Mixins were, and have begun to get the gist
Jeff has previously blogged about using the cache to perform "out of band" processing
I just got Delphi 2009 and have previously read some articles about modifications that
I am looking to develop a website mostly consisting of static pages. I need
I am a php developer using mostly CakePHP, magento, and wordpress. I want to
This is more of a theoretical question rather than language specific, but I'm mostly
I am working on a pure jquery/js site, mostly to practice some jquery. I

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.