Closed nizsheanez closed 11 years ago
1) Why CMap have 'readonly' property but it's not using now?
It can be used in children classes.
2) Why CMap::itemAt don't return by reference?
Push values by reference and it will return references.
That happen when we try to edit CMap on level 2 or deeper, like this - $items[$i]['label'] = 'some_label'
If shortly, PHP happen :-) More about "Indirect modifications of overloaded elements" and why it happens you can find easy.
1) Actually it's used. Check code again.
1) Yep, sorry 2)
Push values by reference and it will return references.
Need to try it tooday,
And need to try sudh values by reference and set readonly=>true
So, i try it.
Push by reference i can't
1 - return parent::__construct(&$data); => Call-time pass-by-reference has been removed
2 - Owerride interface of __construct or add methods too cant, they must compatibile with CMap,
3 - RecursiveArrayAccess like this:
__construct($data)
{
foreach ($data as $key => $val)
{
if (is_array($val))
{
$this->add($key, new self($val, false));
}
else
{
$this->add($key, $val);
}
}
}
too not working with: array_values https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/CMenu.php#L295
4 - Implement Iterator and IteratorAgregate same time i too can't
May be then its good idea to make own class for own needs?
May be. I even have a similar class at work. But using CMenu or CForm with CConfiguration also not bad idea :-)
you do not need to add & when data is an object. objects are given by reference in php by default. I can't see a problem with data as reference here.
That happen when we try to edit CMap on level 2 or deeper, like this - $items[$i]['label'] = 'some_label'
this is not possible with php array interface.
1) Why CMap have 'readonly' property but it's not using now? 2) Why CMap::itemAt don't return by reference? If i want use CConfiguration for example and send it to CMenu, than i have exception "Indirect modification of overloaded element of СConfiguration has no effect" on string https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/CMenu.php#L270
That happen when we try to edit CMap on level 2 or deeper, like this - $items[$i]['label'] = 'some_label'
But, I don't know how we can implement 'readonly' feachure if CMap::itemAt will return by reference.