我写了这个小测试类只是为了说明我的问题
当处理大量数据时,我通常会创建一个继承自 ArrayObject 的类,以更好地构造我的对象并获得一些速度(在 php 5.3 中它快得歇斯底里)。
在任何常规 php 页面中,这都可以正常工作,但在 Joomla 1.7 中使用它时,对象返回已修改。
这是课
// 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;
}
}
在任何常规 php 应用程序中,它都会返回
TestingArrayObject Object
(
[Records] => 10
[storage:ArrayObject:private] => Array
(
[0] => TestObject Object
(
[id] => 0
[name] => yyhjn
)
[1] => TestObject Object
(
[id] => 1
[name] => ausoan
)
...
但在 Joomla 中它返回
TestingArrayObject Object
(
[0] => TestObject Object
(
[id] => 0
[name] => fwwuxg
)
[1] => TestObject Object
(
[id] => 1
[name] => vevimvbk
)
...
所以它跳过了除了非常烦人的数组对象之外的所有内容,因为文档(无论如何都很糟糕)没有涵盖这种行为。我正在编写更大的框架,这些框架依赖于这种设计模式才能工作,所以我不想重新设计所有东西!:)
任何建议从哪里开始?