Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP pthreads命名空间传递问题_Php_Multithreading_Pthreads_Xdebug - Fatal编程技术网

PHP pthreads命名空间传递问题

PHP pthreads命名空间传递问题,php,multithreading,pthreads,xdebug,Php,Multithreading,Pthreads,Xdebug,我在开发支持pthreads的应用程序时遇到了一个问题。如果我不调用pthreads函数start()一切都按计划工作。但是通过调用start()函数,名称空间被破坏(我想是这样),我的类什么也不做。以下是示例: namespace LF\Utility; use LF\Utility\Callme; class Threaded extends \Thread { public function __construct(){ //Constructor stuff

我在开发支持pthreads的应用程序时遇到了一个问题。如果我不调用pthreads函数
start()
一切都按计划工作。但是通过调用
start()
函数,名称空间被破坏(我想是这样),我的类什么也不做。以下是示例:

namespace LF\Utility;
use LF\Utility\Callme;

class Threaded extends \Thread {

    public function __construct(){
        //Constructor stuff
    }

    public function run(){
        echo "in thread";
        $test = new Callme(1);
    }
}
还有Callme:

namespace LF\Utility;

class Callme {

    public function __construct($val)
    {
        echo "num: " . $val;
    }

}
使用
$thread->run()
会给出正确的结果,调用
$thread->start()
不会调用
Callme
构造函数。第二件事是我不能用xDebug调试代码的线程部分,有什么简单的方法可以做到这一点吗


谢谢你的时间

下面的代码对我来说很好

<?php
namespace LF\Utility;

require_once 'callme.php';

use LF\Utility\Callme;

class Threaded extends \Thread {

    public function __construct(){
        //Constructor stuff
    }

    public function run(){
        echo "in thread" . PHP_EOL;
        $test = new Callme(1);
    }
}

$t = new Threaded();
$t->start();

我正在使用traits加载那个类,我不想使用
require
/
requure\u一次,因为它必须使用
use
调用,否则我会丢失所有其他已经加载的类,或者我必须以荒谬的方式调用它们,例如
base\LF\Profile\ClassName
哦,正如我所写的那样-它可以使用$t->run(),只要开始就可以了()导致此问题。@麻烦从我的代码中可以看出,start()可以正常工作。您需要在::run中设置自动加载器