I am trying to execute a function inside a Thread though I get the error "Class 'Example' not found" where example is some custom written class. When executing the function normal (not in a thread) everything works fine.
My guess:
inside the function I call "call_user_func_array" which is executing another function in which the custom class is used in. Can it be that the thread is not able to access this "outside" information.
If so, any recommendations on how to fix the issue?
<?php
$task = new class extends Thread {
public $code;
public $data;
public function run() {
$sample_class = new \SirJoe\Sample_Class();
$this->data = (array) get_all_data($sample_class, $this->code);
}
};
$task->code = $media->getCode();
$task->start();
$task->join();
function get_all_data($sample_class, $code) {
// key of end cursor
$data = call_user_func_array(
array($sample_class, 'getMediaLikesByCode'),
array($code)
);
return $data;
}
inside Sample_Class:
public function getMediaLikesByCode($code, $maxId = null) {
$likeArray(fetchLikes($code, $maxId));
$like = Like::create($likeArray['node']);
return $data;
}
The Likes Class:
<?php
namespace SirJoe\Model;
class Like extends AbstractModel
{
/**
* @var
*/
protected $id;
/**
* @var Account
*/
protected $username;
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getUserName()
{
return $this->username;
}
/**
* @param $value
* @param $prop
*/
protected function initPropertiesCustom($value, $prop)
{
switch ($prop) {
case 'id':
$this->id = $value;
break;
case 'username':
$this->username = $value;
break;
}
}
}
Uncaught Error: Class 'SirJoe\Model\Like' not found in lorem-ipsum.php:999