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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:10:39+00:00 2026-06-12T10:10:39+00:00

I am wondering what method is considered best practice, and why? Having the function

  • 0

I am wondering what method is considered best practice, and why?

Having the function so it attempts to grab whatever is passed in.

class Test{

    private $first = 'first';
    private $second = 'second';

    public function data($what){
        return $this->{strtolower($what)};
    }

}

or having a fixed set of options:

class Test{

    private $first = 'first';
    private $second = 'second';

    public function data($what){
        switch(strtolower($what)){
            case 'first':
                $value = $this->first;
                break;
            case 'second':
                $value = $this->second;
                break;
            default:
                $value = null;
        }
        return $value;
    }

}

Using the first option means that I don’t need to alter the function every time I add a new member to the class, but it also means that I can no longer have private class members.

Using the second options means I need to alter the function every time I add a new member, but it means that I can make sure nothing is read that shouldn’t be.

With the first method if I want to add extra processing to particular members I can just add an if statement for those members.

With the second method I can do the processing inside the case statement.

  • 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-12T10:10:40+00:00Added an answer on June 12, 2026 at 10:10 am

    Surely the code needs to know what to extrapolate from an object Dynamic is not better, being specific is not being sloppy with writing code. It means that you have used you brains to think about the consequences of that action.

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

Sidebar

Related Questions

I'm wondering what is considered best practice for dealing with forms submitted via ajax.
I am wondering what is considered best practice when passing info from a controller
Wondering what others do / best practice for communicating between layers. This question relates
I am wondering which one of these would be considered the cleanest or best
I'm wondering what the best practice is in reporting back to the browser about
I'm just wondering which method is the most effective if I'm literally just wanting
I'm wondering if there is a method in PHP for getting the values of
I was wondering if there is a method for replacing text with a span
I'm wondering why there is a -arrayForKey: method, but no -setArrayForKey: method. How could
I was wondering what the parameters from this method would return. - (void) observeValueForKeyPath:(NSString

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.