Unable to compile ArrayObject class.
http://php.net/manual/en/class.arrayobject.php This class is a part of SPL since version 5.0.0.
creating CPP files...
creating CPP files took 0'00" (61 ms) wall time
[1, {
"UnknownBaseClass":
[{"c1":["test.php",0,0,3,9],"d":"arrayobject","s":0,}
]
}]
It looks like a lot of SPL code is not supported.
FYI This breaks phpMyAdmin
It also makes impossible to compile Propel-based applications
Looks like these people started a native PHP class version, which is likely the best path: http://trac.agavi.org/browser/branches/hiphop/src/hiphop/ArrayObject.php
I've seen it, but it is not functional, it is just a stub. Propel, for example, relies heavily on ArrayObject and others.
Any news on arrayobject class in hiphop??
The Zend Framework also uses ArrayObject heavily, so doesn't work under hhvm.
Here's a simple PHP implementation, it's not fully tested and doesn't support the flags, but it seems to work fine for me!
I'm using both Zend Framework and Propel. Had to make a minor adjustment to PropelCollection::getIterator(), replaced $this->iterator = new ArrayIterator($this); with $this->iterator = parent::getIterator();.
Probably not necessary for you, but I also had to declare RecursiveFilterIterator, took the implementation from here http://php.net/~helly/php/ext/spl/files.html.
class ArrayObject implements IteratorAggregate, Traversable, ArrayAccess, Serializable, Countable
{
const STD_PROP_LIST = 1;
const ARRAY_AS_PROPS = 2;
protected $_array = array();
protected $_flags = 0;
protected $_iterator_class = 'ArrayIterator';
public function __construct ($input = array(), $flags = 0, $iterator_class = 'ArrayIterator')
{
$this->_array = (array)$input;
$this->_flags = $flags;
if ($iterator_class)
$this->_iterator_class = $iterator_class;
}
public function append($value)
{
array_push($this->_array, $value);
}
public function asort()
{
asort($this->_array);
}
public function count()
{
return count($this->_array);
}
public function exchangeArray($input)
{
$this->_array = (array)$input;
}
public function getArrayCopy()
{
return $this->_array;
}
public function getFlags()
{
return $this->_flags;
}
public function getIterator()
{
$cls = $this->_iterator_class;
return new $cls($this->_array);
}
public function getIteratorClass()
{
return $this->_iterator_class;
}
public function ksort()
{
ksort($this->_array);
}
public function natcasesort()
{
natcasesort($this->_array);
}
public function natsort()
{
natsort($this->_array);
}
public function offsetExists($index)
{
return array_key_exists($index, $this->_array);
}
public function offsetGet($index)
{
return $this->_array[$index];
}
public function offsetSet($index, $newval)
{
if(null === $index)
$this->_array[] = $newval;
else
$this->_array[$index] = $newval;
}
public function offsetUnset($index)
{
unset($this->_array[$index]);
}
public function serialize()
{
return serialize($this);
}
public function setFlags($flags)
{
$this->_flags = $flags;
}
public function setIteratorClass($iterator_class)
{
$this->_iterator_class = $iterator_class;
}
public function uasort($cmp_function)
{
uasort($this->_array, $cmp_function);
}
public function uksort($cmp_function)
{
uksort($this->_array, $cmp_function);
}
public function unserialize($serialized)
{
$tmp = unserialize($serialized);
$this->_array = $tmp->_array;
$this->_flags = $tmp->_flags;
$this->_iterator_class = $tmp->_iterator_class;
}
}
Thanks Jesper. Was adding this sufficient to get Zend Framework to work in HHVM, or did you bump into another SPL or other unsupported extension?
Hi,
I tried to improve your code by overloading the sets and gets, but the Zend Framework had Problems when Loading the Plugin BaseUrl....
Would be nice to have the ArrayObject implemented the right way in hhvm.
Additions to Jespers class:
public function __set($name, $value)
{
$this->_array[$name] = $value;
}
public function __get($name)
{
if (array_key_exists($name, $this->_array)) {
return $this->_array[$name];
}
return null;
}
public function __isset($name)
{
return isset($this->_array[$name]);
}
public function __unset($name)
{
unset($this->_array[$name]);
}
We're closing out all bugs older than 2 months. http://www.hiphop-php.com/wp/?p=575
If this is still an issue, please re-open it, and in order of goodness:
- Give detailed repro steps
- Write a test case in hphp/tests/quick (run it with hphp/tests/run) and send the pull request
- Fix it in a pull request