【发布时间】:2015-01-07 15:19:28
【问题描述】:
我正在尝试为使用 pthread 的 codeigniter 创建一个库,一切正常,但是当我想为数组分配一个值时,这不适用于传统的 $a['key'] = 'val';
小测试示例:(更新)
class Test {
protected $core;
protected $stack;
public function init(){
$this->stack = new Test_Stack();
$this->core = new Test_Core($this->stack);
}
public function do_test(){
return $this->core->assign();
}
}
class Test_Stack extends Stackable {
protected $a;
function __construct(){
$this->a = array();
}
protected function test(){ // Call from other class extends Threads
$this->a['key1'] = 'NOWORK';
print_r($this->a); // THIS RETURN NOTHING
$this->a = array_merge($this->a, array('key1' => 'WORK'));
print_r($this->a); // NOW THIS GOOD RETURN Key1..
}
public function run(){}
}
class Test_Core {
protected $thread;
protected $stack;
function __construct($s){
$this->stack = $s;
}
public function assign(){
$this->thread = new Test_Thread($this->stack);
$this->thread->start();
$this->thread->join();
}
}
class Test_Thread extends Thread{
protected $stack;
function __construct($s){
$this->stack = $s;
}
public function run(){
$this->stack->test();
}
}
我在没有测试的情况下编写了这个基本代码,但它与我的 lib 的结构相同,并且需要它来扩展 test_stack 并添加或更改测试函数,例如。
即使现在可以工作,我也会明白为什么我不能正常分配我的数组? 或者更确切地说,我做错了什么?
【问题讨论】:
-
对我来说很好用!我得到的输出:
Array ( [key1] => NOWORK ) Array ( [key1] => WORK ) -
好吧,这很奇怪,我将发布更像我的实现的新代码。谢谢Rizier123
-
您是否启用了通知?
-
是 Marek,error_reporting = E_ALL,display_error On 并且什么都没有出现
标签: php arrays codeigniter pthreads