hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

Unable to compile ArrayObject class.

Open Majkl578 opened this issue 16 years ago • 11 comments

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,}
]
}]

Majkl578 avatar Mar 02 '10 21:03 Majkl578

It looks like a lot of SPL code is not supported.

ezyang avatar Mar 08 '10 22:03 ezyang

FYI This breaks phpMyAdmin

ArloL avatar Aug 17 '10 05:08 ArloL

It also makes impossible to compile Propel-based applications

lvu avatar Feb 09 '11 12:02 lvu

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

joelastpass avatar Mar 03 '11 18:03 joelastpass

I've seen it, but it is not functional, it is just a stub. Propel, for example, relies heavily on ArrayObject and others.

lvu avatar Mar 04 '11 10:03 lvu

Any news on arrayobject class in hiphop??

sandeepuno avatar Sep 18 '11 09:09 sandeepuno

The Zend Framework also uses ArrayObject heavily, so doesn't work under hhvm.

ctoomey avatar Nov 16 '12 07:11 ctoomey

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;
    }
}

deadbeef84 avatar Dec 04 '12 10:12 deadbeef84

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?

ctoomey avatar Dec 05 '12 18:12 ctoomey

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]);
}

sgreiner avatar Apr 12 '13 13:04 sgreiner

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:

  1. Give detailed repro steps
  2. Write a test case in hphp/tests/quick (run it with hphp/tests/run) and send the pull request
  3. Fix it in a pull request

ptarjan avatar May 13 '13 22:05 ptarjan