Skip to content

[Draft][Bug] Undefined constant. #374

Description

@inilim

I'm still studying this issue, and I can't reproduce the error in a simple code. The error only occurs in the production project. Once I reproduce the error, I will update the question or even delete it.

use parallel\Future;
use parallel\Runtime;

class Flow
{
    protected Runtime $runtime;

    function exec(\Closure $callback, array $args = []): Task
    {
        // some code...

        $wrapTask = static function (\Closure $task, string $taskId, array $args) {
            /** @var (null|bool|int|float|string|\Closure|mixed[])[] $args */

            try {

                var_dump([
                    \Inilim\IPDO\IPDO::FETCH_IPDO_RESULT, // int(0) - value of the constant is correct
                    \defined('\Inilim\IPDO\IPDO::FETCH_IPDO_RESULT'), // bool(false) - first bug
                ]);

                \FLOW_TASK_REP->worked($taskId); // throw exception... second bug is related to the first bug, I think
                // "FLOW_TASK_REP" - this constant was defined in the previous task.

                $result = Other::timedMsCall(static function () use ($task, $args) {
                    try {
                        return $task(...$args);
                    } catch (\Throwable) {
                        return null;
                    }
                });

                \FLOW_TASK_REP->success($taskId, \json_encode([
                    'value' => $result['result'],
                    'time'  => $result['time'],
                ]));
            } catch (\Throwable $e) {
                VD::dde([
                    $e->getMessage(), // "Undefined constant Inilim\IPDO\IPDO::FETCH_IPDO_RESULT"
                    $e->getFile(),
                    $e->getLine(),
                ]);
            }
        };

        $this->futures[$task->id] = $this->runtime->run($wrapTask, [$callback, $task->id, $args]);

        return $task;
    }
}

Inside the "worked" method, there is a nested method with an argument that has a default value for a constant.

use Inilim\IPDO\IPDO;

// some code...

protected function internalMethod(
        \Closure $callback,
        string $sql,
        array $values = [],
        int $fetch = IPDO::FETCH_IPDO_RESULT
    ) {...}

PHP

PHP 8.4.9 (cli) (built: Jul  1 2025 15:27:25) (ZTS Visual C++ 2022 x64)
Copyright (c) The PHP Group
Zend Engine v4.4.9, Copyright (c) Zend Technologies

parallel version => 1.2.11
opcache - off

OS
Windows 10 Pro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions