If you run the following code:
$l = new IndexLayout(); $l->setTabPanel( 'foobar' );
it will result in a PHP notice:
Notice: Undefined index: foobar in path/to/IndexLayout.php on line 120
And you'd get a similar notice with getTabPanel.
I think if the panel is not defined, these methods should either throw an exception or use a fallback, but not emit any PHP notices if the element does not exist in the array. I would say that throwing an exception would be better than accepting garbage, but the JS counterpart doesn't throw any error, so perhaps the fallback would be better.
Also, the code and documentation are slightly confusing:
/** * @return TabPanelLayout Tab panel, if found */ public function getTabPanel( $name ) { return $this->tabPanels[$name]; }
The return type should be nullable here, especially because it says "if found" (although it doesn't actually check whether it was found).
public function setTabPanel( $name ) { // ... $tabPanel = $this->getTabPanel( $name ); // ... if ( $tabPanel ) { // ... } }
The code also expects $tabPanel to be falsey, which agrees with the comment but not with the documentation.
Without diving deep into git blame, my first guess is that this code was ported from JavaScript, where accessing unset array elements does not emit any error, and that index checks were simply forgotten in the PHP code.