Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Dynamic Object Names [duplicate]

Possible Duplicate:
Get PHP class property by string

This is my original code:

function generateQuery($type, $language, $options)
{
    // Base type
    $query = $this->Queryparts->print['filter'];

    // Language modifiers
    // Additional options

    return $query;
}

The "print" is an array/hash defined as an object (with "(object)" casting). I wish to do something like this:

    $query = $this->Queryparts->$type['filter'];

To use the the $type variable as the object name. Is this possible?

like image 462
Jonas Ballestad Avatar asked Nov 23 '12 09:11

Jonas Ballestad


1 Answers

$query = $this->Queryparts->{$type}['filter'];
like image 162
som Avatar answered Oct 01 '22 19:10

som