Type hinting for arrays with keys

Is it possible to hint at the types for an array when it has a key? For example


class Table{
    //Stores information about SQL tables
}

function testFunction(){

    $tables = array();

    $tables['comments'] = new Table();

    $tables['users'] = new Table();

    testFunction2($tables);

}

/**

*  @param $tables <-- what goes here?

*/

function testFunction2($tables){


    foreach($tables as $index => $table){

    }

}

Please can you tell me what I should put to hint that $index is a string and $table is a Table.

Apologies if this has been asked many times before but I couldn't see an answer.

2 comments

Hi Dan,

I guess you are talking about how to describe an array with each element of Table type. If so: Table[]

/**

*  @param Table[] $tables Parameter description

*/

function testFunction2($tables){


    foreach($tables as $index => $table){

 

    }

}

0

Please sign in to leave a comment.