TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Undefined variables issues (http://www.talkphp.com/absolute-beginners/2786-undefined-variables-issues.html)

JabberGabber 05-09-2008 10:33 AM

Undefined variables issues
 
Help !

What am I missing here ??

I have the following:

PHP Code:

class Test
{
  var 
$var1;
  
  function 
Set($var1)
  {
     
$this->$var1 $var1;
  }
  function 
Show()
  {
    echo 
$this->$var1;
  }
}

$Test = new Test();
$Var 1;
$Test->Set($Var);
$Test->Show() 

and I get a Undefined Variable var1 ... cannot access empty property .... error message for the line

$this->$var1 = $var1;

Any ideas anyone .... thanks in advance

JabberGabber

Wildhoney 05-09-2008 10:52 AM

php Code:
class Test
{
  var $var1;
 
  function Set($var1)
  {
     $this->var1 = $var1;
  }
  function Show()
  {
    echo $this->var1;
  }
}

The only thing you did wrong was you had $this->$var1, instead of $this->var1.

JabberGabber 05-09-2008 11:02 AM

Excellent - thanks very much for that - I missed the fact you need to drop the $ when you use $this-> - I am getting there slowly ! lol

Wildhoney 05-10-2008 01:55 AM

Keep practising and you'll soon be there :-) !


All times are GMT. The time now is 05:11 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0