Jump to content

[SOLVED] Function variables :S


rockinaway

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.