2014-06-20 2 views
0

PHP 용 pthread를 방금 설치했습니다. 그러나 스레드 클래스의 개체를 만들었습니다. 객체 멤버 변수는 objec을 만들 때 초기화되지 않습니다.PHP pthreads 객체 변수가 초기화되지 않았습니다.

$request = new CopyFile('123','123','123','123','123'); 

을하지만 $ 요청의 변수는 초기화되지 않은 있습니다, 그녀는 내 코드

왜 나는 다음과 같이 내가 새로운 객체를 생성 모른다. CopyFile의 생성자로 들어갈 수 있습니다. 그리고 생성자가 매개 변수 값을 받고 값이 $ this로 전달됨을 발견했습니다.

Thread 클래스 :

class CopyFile extends Thread { 
public $file; 
public $extension; 
public $location; 
public $type; 

public function __construct($file,$extension,$location,$type,$id){ 
    $this->$file = $file; 
    $this->$extension = $extension; 
    $this->$location = $location; 
    $this->$type = $type; 
    $this->$id = $id;  
} 

public function run(){ 

    $key = $this.$location . '/' . $this.$id . '.' . $this.$extension;  

    log::info($result); 
} 
} 

답변

0

귀하의 생성자는 다음과 같이해야한다 올바르지 않습니다. 마찬가지로

$key = $this.$location . '/' . $this.$id . '.' . $this.$extension; 

당신은 또한

같은 변수 ID 뭔가를해야 할 수도 있습니다

$key = $this->location . '/' . $this->id . '.' . $this->extension; 

이어야한다 다음과 같은 구문

$this->var_name = 'some_val' ; // no $ sign before the variable name 


public function __construct($file,$extension,$location,$type,$id){ 
    $this->file = $file; 
    $this->extension = $extension; 
    $this->location = $location; 
    $this->type = $type; 
    $this->id = $id;  
} 

필요 값 또는 액세스 멤버 변수를 지정하려면

public $id ; 
+0

감사합니다. Abhik. 나는 그것에 많은 시간을 보냈다. 당신은 잠시 후에 나의 문제를 해결했습니다. 객체 지향 구문에 대해 더 알아야합니다. –

+0

당신은 가장 환영받으며 그렇습니다. 좋은 예가 PHP 매뉴얼에서 확인하십시오. –

관련 문제