Created
December 10, 2013 16:01
-
-
Save paq85/7893044 to your computer and use it in GitHub Desktop.
PHPDoc of Array Key ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
{ | |
/** | |
* @type array [ | |
* @key string Bar ID (MD5) | |
* @value Bar $bar | |
* ] | |
* | |
* OR | |
* | |
* @type array ( | |
* @type string $key Bar ID (MD5) => @type Bar $value | |
* ) | |
* | |
* ??? | |
*/ | |
private $bars; | |
public function addBar(Bar $bar) | |
{ | |
$this->bars[$bar->getId()] = $bar; | |
} | |
public function findBarById($barId) | |
{ | |
/** | |
* Thanks to the fact I know $this->bars Key is Bar::id I don't have to iterate through the whole array | |
* and check if ($barId === $bar->getId()) | |
*/ | |
if (isset($this->bars[$barId])) { | |
return $this->bars[$barId]; | |
} | |
return false; | |
} | |
} |
Why not:
<?php
class Foo
{
/**
* @var Bar[string]
*/
private $bars;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about: