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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:07:00+00:00 2026-06-12T15:07:00+00:00

I searched, and found this question, which helped me: php static variable is not

  • 0

I searched, and found this question, which helped me:
php static variable is not getting set

It did, however, not solve my entire problem.

Code:

Class DummyClass {
    public static $result;

    function __construct() {
        $this->_setResultCode('testing');
    }

    public function getResultCode() {
        return self::$result['code'];
    }

    private function _setResultCode($val) {
        echo 'Im gonna set it to: ' . $val . '<br />';
        self::$result['code'] = $val;
        echo 'I just set it to: ' . $this->getResultCode;
        die();
    }
}

Outputs:

Im gonna set it to: testing
I just set it to:

What’s going on here? How is this even possible?


EDIT: The problem was i missed the parentheses when calling getResultCode(). HOWEVER, i have another issue now. I can’t seem to get the resultCode out of the class (later on in another instance of DummyClass).

Here is my relevant coded (No more example code because i seemed to mess that up):

Class lightweightContactFormPlugin {

// Set up/Init static $result variable
public static $result;

function __construct() {
    //echo 'I just inited<br/><pre>';
    //var_dump($this->getResultCode());
    //echo '</pre><br/>';
}

public function run() {

    // Set default value for resultCode
    $this->_setResultCode('no_identifier');

    // Check if form was posted
    if(isset($_POST['cfidentifier'])) {
        $fields = $this->_get_fields_to_send();
        $valid = $this->_validate_fields($fields);

        // Only continue if validatation was successful
        if($valid == true) {
            // Store mail result in $mail
            $mail = $this->_send_mail($fields);

            // Yay, success!
            if($mail) {
                $this->_setResultCode('sent_successfully');
                return;
            } else {
                // Couldn't send mail, bu-hu!
                $this->_setResultCode('not_sent');
                return;
            }
        }
        $this->_setResultCode('validation_fail');
        return;
    }
}


    // Get and Set methods
public function getResultCode() {
    return isset(self::$result['code']) ? self::$result['code'] : '';
}

private function _setResultCode($val) {
    self::$result['code'] = $val;
}
}

Left some irrelevant methods out. None of the other methods set or get the resultCode, it shouldn’t matter.

Any ideas why i can’t access $result[‘code’] in another instance of the object (further down the page)?

I do this when i access it:

    $plugin = new lightweightContactFormPlugin();
    $cfstat = $plugin->getResultCode();
    echo '<pre>';
    var_dump($fstat);
    echo '</pre>';

Result is:

NULL

The strange thing is, if i uncomment the code in __construct(), the CORRECT value does get printed out! But if i try to access it from getResultCode() after, it returns NULL again. What is going on?

  • 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-12T15:07:02+00:00Added an answer on June 12, 2026 at 3:07 pm
    echo 'I just set it to: ' . $this->getResultCode;
    

    I think you’re missing a few parenthesis here.

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

Sidebar

Related Questions

I've searched around for answers to this question, but not found anything quite on
Sorry if this is a duplicate question...I've searched around and found similar advice but
I've searched for an answer and found some c#-examples, but could not get this
i have searched the web relentlessly for this and have not found anything -
I found this question, which appears to describe the problem I am currently having,
   I have searched on SO about this question, but I basically haven't found
I searched for this and found Maudite's question about text editors but they were
I searched for a while on this topic and found some results too, which
Simple question, I searched over there and didnt found a way to make this.
I searched about this question but can't found any suitable answer: I had been

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.