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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:52:15+00:00 2026-05-27T15:52:15+00:00

Simple question here… I was wondering if it’s possible to access class propertys by

  • 0

Simple question here… I was wondering if it’s possible to access class propertys by it’s name in any way.

Imagine this scenario:

$array = array(
    'foo' => 'bar',
    'hello' => 'world',
    'chuck' => 'norris'
);

And then have this class:

class MegaClass {
    public $foo, $hello, $chuck;
}

I was wondering if I could set MegaClass::foo to bar, MegaClass::hello to world and so on, automatically. So, given the array, and given the object, the object is filled. This could be really handy when retreiving data from a form with properties filled…

  • 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-05-27T15:52:16+00:00Added an answer on May 27, 2026 at 3:52 pm

    Well for one thing if you wanted to do MegaClass::foo they would have to be static.

    And if they were static you could do:

    foreach($array as $key=>$val){
        MegaClass::$key = $val;
    }
    

    And if they were not static (but were still public):

    foreach($array as $key=>$val){
        $MegaClassObject->$key = $val;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple question here: is there any way to convert from a jagged array to
a simple question here Is there a way to change the text click here
I'm pretty sure this is a simple question in regards to formatting but here's
Simple question. Here is this code. $r = rand(0,1); $c = ($r==0)? rand(65,90) :
Here's a deceptively simple question: What is the proper way to asynchronously play an
This is my first question here and I hope it is simple enough to
Simple question here (though perhaps not such a simple answer): Is it possible to
So the question here is pretty simple: is there a way to tell if
hopefully a simple question here, i have a barcode scanner using Zxing, this is
I'm actually surprised that I didn't find the answer to this simple question here.

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.