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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:05:57+00:00 2026-06-02T23:05:57+00:00

This Class gives me a blank output even if I change return to echo,

  • 0

This Class gives me a blank output even if I change return to echo, I’m not sure what the issue is but I’m obviously not that versed in dealing with Classes and Objects.

I’m sure I’m just handling the variables/arrays incorrectly, but I can’t see where, maybe the variables shouldn’t be declared under Class since they should only be returned if a person is created? Should I declare variables in the function, or not declare them at all since they should be handled by $args?

Updated Question: How do I get it to return every argument not just FIRSTNAME?

PHP:

class people_handler
{
    public $firstname;
    public $middlename;
    public $lastname;
    public $city;
    public $province_state;
    /* zip+4 is default for postcode (postal code) */
    public $postcode;
    public $country;

    function create_people($args)
    {
        $fullname=array($this->firstname,$this->middlename,$this->lastname);
        $normname=array($this->firstname,$this->lastname);
        $fulladdress=array($this->city,$this->province_state,$this->postcode,$this->country);
        if(!$args->middlename&&$args->firstname && $args->lastname && $args->city && $args->province_state && $args->postcode && $args->country)
        {
            $temp_arr=array($normname,$fulladdress);
            foreach($temp_arr as $value)
            {
                foreach($value as $values)
                {
                    return $values;
                }
            }
        }
        else if($args->firstname && $args->middlename && $args->lastname && $args->city && $args->province_state && $args->postcode && $args->country)
        {
            $temp_arr=array($fullname,$fulladdress);
            foreach($temp_arr as $value)
            {
                foreach($value as $values)
                {
                    return $values;
                }
            }
        }
        else
        {
            die ("Must enter all values excluding middlename.");
        }
    }
}

$p1=new people_handler;
$p1->firstname="John";
$p1->middlename="Jonah";
$p1->lastname="Jameson";
$p1->city="Lansing";
$p1->province_state="Michigan";
$p1->postcode="48876-4444";
$p1->country="USA";


echo $p1->create_people($p1);

Returns:

John
  • 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-02T23:05:58+00:00Added an answer on June 2, 2026 at 11:05 pm

    You’re missing the Object self-reference: $this all over the place.

    Anytime you refer to a method or property from within the class, you need to refer to $this as the current instantiation of the Object that is doing the process. So, for instance…

    $fullname=array($firstname,$middlename,$lastname);  
    

    becomes

     $fullname=array($this->firstname,$this->middlename,$this->lastname);  
    

    Which should work, since you assigned the values to those properties already.

    EDIT: Looking at the code further, constantly returning a value through loops won’t manage the echoing to the browser. You can either echo $value instead of returning it, or build an array from the values and return that and have the script handle the array to echo to the browser.

    EDIT THE SECOND: To get all the values out, you need to collect them as you build them. Another option is to simply output them to the browser as part of the method. Both options work, but collecting them into an array makes it more portable, but also a fair bit more code to maintain. As well, you do not need to pass the object into itself to get the method to work.

    echo $p1->create_people($p1);
    

    Should be…

    $p1->create_people();
    

    In create_people you’ll have…

    function create_people()
    {
        $fullname=array($this->firstname,$this->middlename,$this->lastname);
        $normname=array($this->firstname,$this->lastname);
        $fulladdress=array($this->city, $this->province_state, $this->postcode, $this->country);
        if($args->firstname && $args->lastname && $args->city && $args->province_state && $args->postcode && $args->country)
        { //Don't bother including middlename if it doesn't matter if it is filled or not...
            $temp_arr = array($normname, $fulladdress);
            foreach($temp_arr as $value)
            {
                foreach($value as $values)
                {
                    echo $values;
                }
            }
        } else {
            die ("Must enter all values excluding middlename.");
        }
    }
    

    That should work.

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

Sidebar

Related Questions

This is really stumping me today. I'm sure its not that hard, but I
g++ compiler gives this error: expected `;' before 'it' template <typename T> class myList
I'm currently using this code: var gallery = $('ul#gallery').children(); $(gallery).filter(':even').not(':last').hover(function () {$(this).toggleClass('next')}); I'm trying
Assuming that I have this navigation bar <div id = nav> <a class =
So the situation is like this. Suppose we have: class Test(datetime): def a(self): return
I have controller methods that look like this: class TestController < ApplicationController def testAction
The output for this activity produces a blank screen with titlebar. What am I
Given this class: class Foo { readonly ILog log; public Foo(ILog log) { this.log
Given this class class Foo { // Want to find _bar with reflection [SomeAttribute]
Given this class public partial class Default : Page { private IRepository repo; ...

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.