Dodam jeszcze, że problem jest tylko na Linuxie (ale to standard, win to wiadomo jakie g*

).
Cytat
1. W PHP nie ma takiej klasy jak ArrayAccess, więc nie możesz po niej dziedziczyć (no chyba, że masz swoją). Jeśli jednak to wynik Twojej pomyłki i miałeś na myśli to, że implementujesz interfejs ArrayAccess to ...
Dzięki za poprawkę, chodziło mi oczywiście o interfejs.
Cytat
2. ... interfejs ArrayAccess posiada cztery metody. Jak masz zaimplementowane pozostałe poza offsetGet()?
Wszystkie odnoszą się do metod magicznych __. Np: offsetGet() z __get() (i analogicznie pozostałe: set, isset [exists], unset).
Wycinka klasy, z której dziedziczy Vframe_Config, w zasadzie Vframe_Config odpowiada tylko za zainicjownaie silnika i pobranie danych, wkłada je w formie tablicy do atrybutu $_aAttributes:
<?php
class Vframe_Attribute implements Countable, Serializable, ArrayAccess, Iterator
{
protected
$_aAttributes = array();
public function dump()
{
return $this->_aAttributes;
}
public function __get($sParam)
{
return $this->__isset($sParam) ? $this->_aAttributes[$sParam] : null;
}
public function __set($sParam, $mValue)
{
return $this->_aAttributes[$sParam] = $mValue;
}
public function __isset($sParam)
{
return isset($this->_aAttributes
[$sParam]); }
public function __unset($sParam)
{
if($this->__isset($sParam))
unset($this->_aAttributes
[$sParam]); }
public function __sleep()
{
}
public function __wakeUp()
{
}
/**
* Serializable
*/
{
}
{
return $this->_aAttributes = $aAttributes;
return false;
}
/**
* Countable
*/
{
return count($this->_aAttributes
); }
/**
* Iterator
*/
{
reset($this->_aAttributes
); }
{
return key($this->_aAttributes
); }
{
return next($this->_aAttributes
); }
{
return current($this->_aAttributes
); }
public function valid()
{
return ($this->current() !== false);
}
// ArrayAccess
public function offsetGet($sParam)
{
return $this->__get($sParam);
}
public function offsetSet($sParam, $mValue)
{
return $this->__set($sParam, $mValue);
}
public function offsetExists($sParam)
{
return $this->__isset($sParam);
}
public function offsetUnset($sParam)
{
$this->__unset($sParam);
}
}
?>
Zrobiłem więc mały test poza środowiskiem frameworka, żeby być pewien na 100%, że to jest nie jest jego wina:
<?php
class Vframe_Attribute implements ArrayAccess
{
protected
$_aAttributes = array();
public function __get($sParam)
{
return $this->__isset($sParam) ? $this->_aAttributes[$sParam] : null;
}
public function __set($sParam, $mValue)
{
return $this->_aAttributes[$sParam] = $mValue;
}
public function __isset($sParam)
{
return isset($this->_aAttributes
[$sParam]); }
public function __unset($sParam)
{
if($this->__isset($sParam))
unset($this->_aAttributes
[$sParam]); }
public function offsetGet($sParam)
{
return $this->__get($sParam);
}
public function offsetSet($sParam, $mValue)
{
return $this->__set($sParam, $mValue);
}
public function offsetExists($sParam)
{
return $this->__isset($sParam);
}
public function offsetUnset($sParam)
{
$this->__unset($sParam);
}
}
class Vframe_Config extends Vframe_Attribute
{
public function __construct()
{
$this->_aAttributes
= array('a' => 1, 'b' => 2, 'c' => array(1
,2
)); }
}
$oConfig = new Vframe_Config();
echo ($oConfig['a'] == $oConfig->b) ?
'Yes' : 'No'; echo ($oConfig['not_exists']) ?
'Exists' : 'Not extsis';
foreach($oConfig['c'] as $iNumber)
echo 'Number ' . $iNumber;
?>
Nie działa pętla foreach. (przepraszam za wprowadzenie w błąd w pierwszym poście). Dzieje się tylko przy pętlach.