Entity throw error when set self in function #7060

Open
opened 2026-01-22 15:43:56 +01:00 by admin · 0 comments
Owner

Originally created by @CuongPhi on GitHub (Oct 13, 2022).

Bug Report

/**
 * @\Doctrine\ORM\Mapping\MappedSuperclass
 */
abstract class User {
    /**
     * @\Doctrine\ORM\Mapping\Id
     * @\Doctrine\ORM\Mapping\Column(type="integer", length=12, nullable=false)
     * @\Doctrine\ORM\Mapping\GeneratedValue(strategy="AUTO")
     */
    protected $id;
    /**
     * @\Doctrine\ORM\Mapping\Column(type="string", length=216, nullable=false)
     */
    protected $name = '';
}
/**
 * @\Doctrine\ORM\Mapping\MappedSuperclass
 */
class User extends Generated\User {
   const JSON_KEYS = [
       'id'         => 'id',
       'name'    => 'name',
  ];
   public function toJsonData( $scopes = self::JSON_KEYS){
        $result = [];
        // ...
        return $result;
    }
}

// Doctrine generated

namespace Proxies\__CG__\Models\Entities;

/**
 * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR
 */
class User extends \Models\Entities\User implements \Doctrine\ORM\Proxy\Proxy
{
 ....
    public function toJsonData($scopes = \self::JSON_KEYS)  // line 794
    {

        $this->__initializer__ && $this->__initializer__->__invoke($this, 'toJsonData', [$scopes]);

        return parent::toJsonData($scopes);
    }

....
}

Summary

PHP Fatal error: '\self' is an invalid class name in ../data/DT_Proxies/__CG__ModelsEntitiesUser.php on line 794

Current behavior

How to reproduce

Update to latest doctrine ORM v2.13.3

Expected behavior

Not error throwing

Originally created by @CuongPhi on GitHub (Oct 13, 2022). ### Bug Report ``` /** * @\Doctrine\ORM\Mapping\MappedSuperclass */ abstract class User { /** * @\Doctrine\ORM\Mapping\Id * @\Doctrine\ORM\Mapping\Column(type="integer", length=12, nullable=false) * @\Doctrine\ORM\Mapping\GeneratedValue(strategy="AUTO") */ protected $id; /** * @\Doctrine\ORM\Mapping\Column(type="string", length=216, nullable=false) */ protected $name = ''; } ``` ``` /** * @\Doctrine\ORM\Mapping\MappedSuperclass */ class User extends Generated\User { const JSON_KEYS = [ 'id' => 'id', 'name' => 'name', ]; public function toJsonData( $scopes = self::JSON_KEYS){ $result = []; // ... return $result; } } ``` // Doctrine generated ``` namespace Proxies\__CG__\Models\Entities; /** * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR */ class User extends \Models\Entities\User implements \Doctrine\ORM\Proxy\Proxy { .... public function toJsonData($scopes = \self::JSON_KEYS) // line 794 { $this->__initializer__ && $this->__initializer__->__invoke($this, 'toJsonData', [$scopes]); return parent::toJsonData($scopes); } .... } ``` #### Summary <!-- Provide a summary describing the problem you are experiencing. --> PHP Fatal error: '\\self' is an invalid class name in ../data/DT_Proxies/__CG__ModelsEntitiesUser.php on line 794 #### Current behavior <!-- What is the current (buggy) behavior? --> #### How to reproduce Update to latest doctrine ORM v2.13.3 <!-- Provide steps to reproduce the bug. If possible, also add a code snippet with relevant configuration, entity mappings, DQL etc. Adding a failing Unit or Functional Test would help us a lot - you can submit one in a Pull Request separately, referencing this bug report. --> #### Expected behavior <!-- What was the expected (correct) behavior? --> Not error throwing
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7060