Skip to content

Setting property default value to enum points to invalid namespace #754

@IonBazan

Description

@IonBazan

When generating a proxy where a default value is enum using PHP 8.1 (yes, I know...), the default value is missing leading slash, pointing to non-existent class.

namespace App\Domain\Transaction;

enum Status: string
{
    case INITIATED = 'INITIATED';
}
class Transaction
{
// ...
    protected Status $state = \App\Domain\Transaction\Status::INITIATED;
}

Generated proxy:

namespace MongoDBODMProxies\__PM__\App\Domain\Document\Transaction\Transaction;

class Generatedd19772223e8a9012106a186d3aa68e25 extends \App\Domain\Document\Transaction\Transaction implements \ProxyManager\Proxy\GhostObjectInterface
{
    private function callInitializer7e974($methodName, array $parameters)
    {
        if ($this->initializationTracker75370 || ! $this->initializer83563) {
            return;
        }

        $this->initializationTracker75370 = true;

        $this->state = App\Domain\Transaction\Status::INITIATED; // note missing leading backslash producing invalid namespace name
        // ...
    }
}

This is caused by var_export which implies root namespace, while generated proxy is its own namespace:

We could either explicitly check for enum_exists and prefix it with \ just to make things work but I'm not sure if it's right solution so just creating an issue to track this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdependenciesPull requests that update a dependency file

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions