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

  • Home
  • SEARCH
  • 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 8528273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:45:54+00:00 2026-06-11T08:45:54+00:00

I have a PHP class with a few static properties like so: static public

  • 0

I have a PHP class with a few static properties like so:

static public $_TYPE_DESIGN_DRAFT = 'design_draft';
static public $_TYPE_STORYTELLING_DRAFT = 'storytelling_draft';
static public $_TYPE_OTHER = 'other';
static public $_TYPE_DATA_FILE = 'data_file';

static public $_ALLOWED_EXTENSIONS = array(       // on the next line it breaks
                self::$_TYPE_DESIGN_DRAFT => array("jpeg", "jpg", "png", "gif", "pdf", "txt", "rtf", "doc", "csv"),
                self::$_TYPE_STORYTELLING_DRAFT => array("jpeg", "jpg", "png", "gif", "pdf", "txt", "rtf", "doc", "csv"),
                self::$_TYPE_OTHER => array("jpeg", "jpg", "png", "gif", "pdf", "txt", "rtf", "doc", "csv"),
                self::$_TYPE_DATA_FILE => array("pdf", "txt", "rtf", "doc", "csv", "xls")
);

But it seems PHP won’t let me define an array like that with the value of the keys as static properties of the same class.

A workaround would be to only define the $_ALLOWED_EXTENSIONS var in the constructor of the class, but then I can’t make it static because when static, the constructor doesn’t get called.

Is there an effective workaround for this?

  • 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-11T08:45:55+00:00Added an answer on June 11, 2026 at 8:45 am

    You cannot use class properties like this.

    Following on from my comment; can you not doing something like this?

    class Test
    {
        static public $_TYPE_DESIGN_DRAFT = 'design_draft';
        static public $_TYPE_STORYTELLING_DRAFT = 'storytelling_draft';
        static public $_TYPE_OTHER = 'other';
        static public $_TYPE_DATA_FILE = 'data_file';
    
        static public $_ALLOWED_EXTENSIONS = array();
    
        public static function init()
        {
            self::$_ALLOWED_EXTENSIONS = array(
                self::$_TYPE_DESIGN_DRAFT => array("jpeg", "jpg", "png", "gif", "pdf", "txt", "rtf", "doc", "csv"),
                self::$_TYPE_STORYTELLING_DRAFT => array("jpeg", "jpg", "png", "gif", "pdf", "txt", "rtf", "doc", "csv"),
                self::$_TYPE_OTHER => array("jpeg", "jpg", "png", "gif", "pdf", "txt", "rtf", "doc", "csv"),
                self::$_TYPE_DATA_FILE => array("pdf", "txt", "rtf", "doc", "csv", "xls")       
            );      
        }
    }
    
    Test::init();
    print_r(Test::$_ALLOWED_EXTENSIONS);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the oop php code: class a { // with properties and functions
Below code works fine: <?php session_start(); $_SESSION['color'] = 'blue'; class utilities { public static
I have a php class, RegistrationController, <?php class RegistrationController extends ParentController { function __construct()
I have certain PHP class methods that access external variables. These variables are not
I have a PHP class that stores a complex multidimensional array, and rather than
I have a php class that generates a map image depending on my db
I have a PHP class with a method. In the base class (it's more
Let's say I have a PHP class called Color , it's constructor accepts various
In php have a class SoapClient I need a equivalente class in Java, anyone
I have turned a normal PHP class into a library so I can use

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.