Hi
I am trying to modify a class and I found this code in it:

$query = " SELECT * FROM menus WHERE show = '1'";
        
        $id = $this->menuid;
        
        if((isset($id)) && ($id != ''))
        {
            $query .= " and menuid in($id)";
        }
        
        $query .= " ORDER BY menuorder ASC";
        
        $result = $db->query($query);

        while($row = $db->dbarray($result))
        {
            @extract($row);
            
            if(($checkuser == 1) && ($_COOKIE['mid'] != $var['Guestid']))
            {
                $menu .= $this->$menutitle();
            }
            elseif(($checkuser == 2) &&  ($_COOKIE['mid'] == $var['Guestid']))
            {
                $menu .= $this->$menutitle();
            }
            elseif($checkuser == 0)
            {
                $menu .= $this->$menutitle();
            }
        }

what does "$this->$menutitle()" refer to? and how does it work? To my understanding you can not put a $ sing after "->" in a class. $menutitle() does not seem to me as a variable neither as a function. What am i missing?

Hi
I am trying to modify a class and I found this code in it:

$query = " SELECT * FROM menus WHERE show = '1'";
        
        $id = $this->menuid;
        
        if((isset($id)) && ($id != ''))
        {
            $query .= " and menuid in($id)";
        }
        
        $query .= " ORDER BY menuorder ASC";
        
        $result = $db->query($query);

        while($row = $db->dbarray($result))
        {
            @extract($row);
            
            if(($checkuser == 1) && ($_COOKIE['mid'] != $var['Guestid']))
            {
                $menu .= $this->$menutitle();
            }
            elseif(($checkuser == 2) &&  ($_COOKIE['mid'] == $var['Guestid']))
            {
                $menu .= $this->$menutitle();
            }
            elseif($checkuser == 0)
            {
                $menu .= $this->$menutitle();
            }
        }

what does "$this->$menutitle()" refer to? and how does it work? To my understanding you can not put a $ sing after "->" in a class. $menutitle() does not seem to me as a variable neither as a function. What am i missing?

That is a variable property in the same why variable variables are created. For example:

// variable variable example
$var = "hello";
$hello = "world";
echo $$var; // world
// variable property example
class TestClass
{
  public $hello;
  public function __construct()
  {
    $this->hello = "World";
  }
}

$test = new TestClass();
$var = "hello";
echo $test->$var; // world

See http://us2.php.net/manual/en/language.variables.variable.php

commented: Useful info - in the category "I should have known that but didn't" +1

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.