Jump to content

Recommended Posts

  
        var $testvar;


        function check_test()
        {
                if (!isset($this->testvar) || $this->testvar = '') echo 'Nothing set!';
        }


function test()
	{

			$this->testvar = 'Test';

			return $this->testvar;
		}		
	}

 

When I try this mt check_test() function always returns the error for the variable being empty or not present, eventhough I have it set in the function test() when it is called.

 

Even if I put test() before check_test() the same thing happens.. what could be the problem?

Link to comment
https://forums.phpfreaks.com/topic/71984-solved-function-variables-s/
Share on other sites

Sorry my mistake.. missed ! :P New code.. still problems.. explained below

 


        var $testvar;

        
function test()
{

			$this->testvar = 'Test';

			return $this->testvar;
		}		
}

        function check_test()
        {
                if (!isset($this->testvar) || $this->testvar != '') echo 'Nothing set!'.$this->testvar;
        }



 

This the new code.. but I found a problem. Eventhough $testvar is a global variable.. as you can see it is set in test()... however if I try retrieving in it check_test() nothing is returned..

 

If I do the following:

 

        function check_test()
        {
                $this->testvar = 'sdasd';
                if (!isset($this->testvar) || $this->testvar != '') echo 'Nothing set!'.$this->testvar;
        }

 

Then it returns the value when it is in it's own function.. but still not the values set in other functions..

 

Why is this?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.