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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:21:02+00:00 2026-06-01T13:21:02+00:00

if I have methods like function getVar1(){ return $this->var1; } function getVar2(){ return $this->var2;

  • 0

if I have methods like

function getVar1(){
  return $this->var1;
}

function getVar2(){
  return $this->var2;
}

and so on…

and these vars are meant to be printed on the screen, is it a good idea to create additional methods that directly print them?

like

   function Var1(){
     echo $this->getVar1();
   }

   function Var2(){
     echo $this->getVar2();
   }

or should I stick with calling echo getVar1() where I need them?

  • 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-01T13:21:03+00:00Added an answer on June 1, 2026 at 1:21 pm

    Functions should do what their name implies. It’s one of the core design principles. When you say getVar(), it does what it’s meant to do: return a variable.

    In your example, you are not even specifying what the function does. If you want to have a function that prints something, then call it printVar1() or something like that.

    On the other hand, I have to agree with ThiefMaster. You can just use echo getVar1() instead of creating bigger classes. Especially in an interpreted language like PHP(where classes add more overhead than a compiled language).

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

Sidebar

Related Questions

I have 2 functions/methods in the same controller in CodeIgniter like this: public function
I have many js methods that uses global variables like: function DoSomething() { var
Assuming I have a function like this my_method(const vector<const T*> & param); I wonder
I have methods in all of my models that look like this: def formatted_start_date
Lot of libraries i have seen methods defined like this Common.deepCopy = Common.deepCopy ||
I have a Person javascript class like function Person(_name, _id, _salary){ this.Name = _name;
I'd like to have a little php module. This module would have methods that
I'm working on a game engine in C++ and I have methods like setColour
I have: @Component class MyDecorator{ private Cache cache; /* some wrapped methods like get
I have a couple of methods I'd like to share between models rather than

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.