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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:43:21+00:00 2026-06-03T07:43:21+00:00

Assume we have some object $a = new stdClass; $a->b = 7; $a->c =

  • 0

Assume we have some object

$a = new stdClass;
$a->b = 7;
$a->c = 'o';
$a->d = array(1,2,3);

Also we have a function which doing something with some of properties of our object (for example b and d[1]).

My question: Should my function accept whole object as a parameter like:

function some($a) {
 var_dump($a->b);
 var_dump($a->d[1]);
}

some($a);

or accept only certain fields which it’s process like:

function some($b, $d) {
 var_dump($b);
 var_dump($d);
}

some($a->b, $a->d[1]);

Actually no matter is $a object or array.

  • 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-03T07:43:22+00:00Added an answer on June 3, 2026 at 7:43 am

    I believe the first option is the way to go.

    function some($a) {
     var_dump($a->b);
     var_dump($a->d[1]);
    }
    
    some($a);
    

    Because maybe over time you will need other parts of that object/array and you will have to modify the function and the calls where you make them.
    So function some() can be a global function and used in other ways, you can add later statements, modify the function without having to modify everywhere.

    function some($a, $param1 = 1){
        if($param1 == 1){
            var_dump($a->c);
            var_dump($a->d[2]);
        } else {
            var_dump($a->b);
            var_dump($a->d[1]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have some C++ method which returns back a pointer to an object.
Let's assume I have a framework written in Java and some C++ code which
I have an application which does some socket communication with some hardwares. Assume for
I'm new to ORM stuff and I need some help understanding something. Let's assume
I'm new in Entity Framework and i have problem with something which was quite
Assume some domain and view objects (that have no common base class) public class
Assume I have the following input in Pig: some And I would like to
Assume you have a file which has been committed in your Git repo. You
Assume we build an object to represent some network (social, wireless, whatever). So we
Lets assume we have a class in python: class A(object): def __del__(self): print Del!

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.