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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:46:12+00:00 2026-06-04T04:46:12+00:00

I am dealing with an object of a class that I did not write

  • 0

I am dealing with an object of a class that I did not write and cannot change.This class has a very large number of attributes. I want to cycle trough about half of these attributes (a select group). I put the names of the nescessary attributes into an array and would like to cycle through them. Is this possible? What is the syntax like?

class B{
   public $foo = 'hi';
   public $bar = 'bye';
   ...etc, etc.
}

$arr = array(1=>'foo', 2=>'bar', ...)
$b = new B();
foreach($arr as $val){
  echo $b->($val); //<-----does not work
}
  • 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-04T04:46:14+00:00Added an answer on June 4, 2026 at 4:46 am

    You were close:

    $b->$val; //Or...
    $b->{$val};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When dealing with events, people are usually taking examples of very simple values object
I've been dealing a lot lately with abstract classes that use generics. This is
I am getting following error: COM object that has been separated from its underlying
What is real difference between Class and Structure when you are dealing with Object
Good afternoon, It is a well known fact that when dealing with large files
I'm dealing with a legacy code base where a class which is not wired
This benchmark appears to show that calling a virtual method directly on object reference
Basically I have run-time loaded class that looks like this: [Plugin(Plugin name)] class PluginActions
I have some code below. This code is a basic push/pop stack class that
I've been dealing with this problem for my thesis. The goal is to develop

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.