Ben aşağıdaki PHP fonksiyonu var
protected function &__group($ar_path, $b_create) {
assert('is_null($ar_path) || is_array($ar_path)');
$parent = &$this->ma_config;
if (!is_null($ar_path) && (count($ar_path) > 0)) {
if ($b_create) {
// Get with Create is necessary
foreach ($ar_path as $group) {
if (!array_key_exists('groups', $parent)) {
/*MARKER*/ $parent['groups'] = array($group => array());
// Mark the File as Modified
$this->mb_dirty = true;
continue;
}
$parent = &$parent['groups'];
if (!array_key_exists($group, $parent)) {
$parent[$group] = array();
// Mark the File as Modified
$this->mb_dirty = true;
continue;
}
$parent = &$parent[$group];
}
} else {
// Simple Get
foreach ($ar_path as $group) {
$parent = array_extract_key(
array('groups', $group),
$parent,
'is_array'
);
if (is_null($parent)) {
break;
}
}
}
}
return $parent;
}
Fonksiyonu bana herhangi bir düzeyde (yani iç içe gruplar) de 'grupları' oluşturmak için izin gerekiyordu.
What seems to be the problem is the way PHP handles references.
When I send in something like ar_path('level 1','level 2')
, the function should create a child group to 'level 1' if it doesn't exist.
Bu nedenle verilen bir şey gibi:
$this->ma_config = array(
'groups' => array(
'level 1' => array(
'values' => array(
'1',
'2'
)
)
)
);
Ben böyle bir şey ile bitmelidir:
$this->ma_config = array(
'groups' => array(
'level 1' => array(
'groups' => array(
'level 2' => array()
),
'values' => array(
'1',
'2'
)
)
)
);
Sorun satırını çalıştırdığınızda döngü içinde benim ikinci geçişte, /*MARKER*/
bu 'seviye 1 yok ($this->ma_config['groups']['level 1]['groups']['level 2'] = array()
sonuçlandı olmalıydı yani) ikinci düzeyde oluşturmak için, yani 'yerine (PHP yapıyor biter, hata ayıklayıcı gibi görünüyor, bunun yerine $this->ma_config['groups']['level 1] = array()
)
Neden?