duanruanxian5028 2019-04-12 10:13
浏览 65

找不到PHP Pthreads类'Example'

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?