Question

I've written this small test class just to illustrate my problem

When working with larger amounts of data I usually create a class that inherits from ArrayObject to better structure my objects and to gain some speed (it's hysterically fast in php 5.3).

In any regular php page this works fine but when using it in Joomla 1.7 the object returns modified.

This is the class

// Call the class
new TestingArrayObject();

class TestingArrayObject extends ArrayObject {

    protected $Records;

    public function __construct() {
        $this->Records = 10;

        for ($index = 0; $index < $this->Records; $index++) {
            $this->append(new TestObject($index, $this->createRandomName()));
        }

        echo "<xmp>";
        print_r($this);
        echo "</xmp>";
    }

    private function createRandomName() {
        $chars = "abcdefghijkmnopqrstuvwxyz";
        srand((double) microtime() * 1000000);
        $i = 0; $pass = '';
        while ($i <= 7)
            $num = rand() % 33; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++;

        return $pass;
    }

    public function append(TestObject $value) {
        parent::append($value);
    }

}

class TestObject {

    public $id;
    public $name;

    public function __construct($id, $name) {
        $this->id = $id;
        $this->name = $name;
    }

}

In any regular php application it return

TestingArrayObject Object
(
    [Records] => 10
    [storage:ArrayObject:private] => Array
        (
            [0] => TestObject Object
                (
                    [id] => 0
                    [name] => yyhjn
                )

            [1] => TestObject Object
                (
                    [id] => 1
                    [name] => ausoan
                )
...

But in Joomla it return

TestingArrayObject Object
(
    [0] => TestObject Object
        (
            [id] => 0
            [name] => fwwuxg
        )

    [1] => TestObject Object
        (
            [id] => 1
            [name] => vevimvbk
        )
...

So it skips everything but the array object which is very annoying since the documentation (which sucks anyway) doesn't cover this behavior. Im writing bigger frameworks which depend on this design pattern to work so I'd prefer not to redesign everything! :)

Any advice where to start?

Était-ce utile?

La solution

It is broken, had to implement the ArrayObject as a property instead

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top