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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:57:15+00:00 2026-05-12T00:57:15+00:00

First thing i want to say that it’s not an easy question to explain,

  • 0

First thing i want to say that it’s not an easy question to explain, so please be patient if it seems confusing.

I have a set of classes like this

class Product {

   public static $static_type = 'product';
   public static $static_table = 'product_table';

   public function __construct($params) { //do some }
}

and then there are the classes News, Events etc

From another class i need to access to those static variables inside these classes in an iterative way. Something like:

//...
if (Product::$static_type) { //do some }
else if (News::$static_type) { //do other }
//...

I want to trasform it in a cycle, like foreach in a way like this (it’s not correct but makes sense to my question)

foreach ($classes as $class) {
  echo $class::$static_type; //brrrr, just to render the idea :)
}

So i think about a singleton/static class that has a static method returning an array of my classes (not instantiated). Like this:

class Conf {

    public function __construct() {
          //nothing
        }

    public static function get_class_array () {

       //how to do this???
    }
}

and then

foreach (Conf::get_class_array() as $class) {
  echo $class::$static_type; //brrrr, just to render the idea :)
}

How i can reach this? I don’t want to instantiate Product, News or others in this case.

Edit: eval is evil, i don’t want to use it. No tricks with get_declared_class, if there’s no way to solve I will use reflection, that i think it’s the more elegant way among the mentioned :(.

Edit: in the meantime i’ll do the Conf::get_class_array() in this way

public static function get_class_array () {
   return array(new ReflectionClass('Prodotto'), new ReflectionClass('News'));
}

and then call it here:

foreach (Conf::get_class_array() as $class) {
  echo $class->getStaticPropertyValue('static_type');
}
  • 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-12T00:57:16+00:00Added an answer on May 12, 2026 at 12:57 am

    I don’t think you can do this. You could however do one of these:

    $properties = get_class_vars('Product');
    echo $properties['static_type'];
    

    or

    $class = new ReflectionClass('product');
    echo $class->getStaticPropertyValue('static_type');
    

    Note that in PHP 5.3 echo $class::$static_type; will work (http://php.net/manual/en/language.oop5.static.php)

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

Sidebar

Related Questions

Say that a page loads and the first thing I want to do is
First I want to say, I'm sorry if this question have be asked already
Lets say that I have a function todo() and I want to implement this
First of all, I need to say that my English is not good. So
First, I want to say that I'm out on deep water here, since I'm
First of all I just want to say that I never understood so well
OK, first thing I want to say is: yes, I know there are a
The first thing that comes to my mind is to do a bunch of
I have some jQuery/JS below. The first thing to run is the alert box
Well, this is the thing. Let's say that my future PHP CMS need to

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.