-
-
Notifications
You must be signed in to change notification settings - Fork 589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notice: Accessing static property Proxies\__CG__\examplemodel\inherit\Customers::$lazyPropertiesNames as non static #1209
Comments
Hi, thanks for your report, but how am I supposed to reproduce the issue? |
Hi, I'm gonna to try to be more explicit Composer dependencies"require": {
"doctrine/orm" : "2.7.*",
"jms/serializer" : "3.7.*",
} Dump SQL importationThe previous file .sql was imported in my MySQL local server Test.phpuse Doctrine\ORM\EntityManager;
use Doctrine\ORM\Configuration;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Proxy\AbstractProxyFactory;
require __DIR__ . '/Customers.php';
require __DIR__ . '/CustomersRepo.php';
require __DIR__ . '/Products.php';
require __DIR__ . '/ProductsRepo.php';
require __DIR__ . '/TypeProducts.php';
require __DIR__ . '/TypeProductsRepo.php';
$config = new Configuration;
$driver = $config->newDefaultAnnotationDriver(__DIR__,false);
$config->setMetadataDriverImpl($driver);
$config->setProxyDir(__DIR__);
$config->setProxyNamespace('Proxies');
$proxy = AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS;
$config->setAutoGenerateProxyClasses($proxy);
$config->setMetadataCacheImpl(new ArrayCache());
$config->setQueryCacheImpl(new ArrayCache());
$em = EntityManager::create([
"driver" => "pdo_mysql",
"host" => "127.0.0.1",
"user" => "root",
"password" => "root",
"dbname" => "examplemodel",
"charset" => "utf8",
"driverOptions" => [
"1002" => "SET NAMES utf8"
]
], $config);
$product = $em->getRepository("examplemodel\\Products")->findAll();
$serializer = JMS\Serializer\SerializerBuilder::create()->build();
var_dump($serializer->serialize($product, 'json')); Entities and repositoriesCustomers Entitynamespace examplemodel;
use Doctrine\ORM\Mapping as ORM;
/**
* Customers
*
* @ORM\Table(name="customers")
* @ORM\Entity(repositoryClass="examplemodel\CustomersRepo")
*/
class Customers
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string|null
*
* @ORM\Column(name="name", type="string", length=100, nullable=true)
*/
private $name;
/**
* @var string|null
*
* @ORM\Column(name="address", type="string", length=100, nullable=true)
*/
private $address;
/**
* @var string|null
*
* @ORM\Column(name="address_extra", type="string", length=100, nullable=true)
*/
private $addressExtra;
/**
* @var string|null
*
* @ORM\Column(name="city", type="string", length=100, nullable=true)
*/
private $city;
/**
* @var string|null
*
* @ORM\Column(name="postal_code", type="string", length=45, nullable=true)
*/
private $postalCode;
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name.
*
* @param string|null $name
*
* @return Customers
*/
public function setName($name = null)
{
$this->name = $name;
return $this;
}
/**
* Get name.
*
* @return string|null
*/
public function getName()
{
return $this->name;
}
/**
* Set address.
*
* @param string|null $address
*
* @return Customers
*/
public function setAddress($address = null)
{
$this->address = $address;
return $this;
}
/**
* Get address.
*
* @return string|null
*/
public function getAddress()
{
return $this->address;
}
/**
* Set addressExtra.
*
* @param string|null $addressExtra
*
* @return Customers
*/
public function setAddressExtra($addressExtra = null)
{
$this->addressExtra = $addressExtra;
return $this;
}
/**
* Get addressExtra.
*
* @return string|null
*/
public function getAddressExtra()
{
return $this->addressExtra;
}
/**
* Set city.
*
* @param string|null $city
*
* @return Customers
*/
public function setCity($city = null)
{
$this->city = $city;
return $this;
}
/**
* Get city.
*
* @return string|null
*/
public function getCity()
{
return $this->city;
}
/**
* Set postalCode.
*
* @param string|null $postalCode
*
* @return Customers
*/
public function setPostalCode($postalCode = null)
{
$this->postalCode = $postalCode;
return $this;
}
/**
* Get postalCode.
*
* @return string|null
*/
public function getPostalCode()
{
return $this->postalCode;
}
} Customers Repository<?php
namespace examplemodel;
use Doctrine\ORM\EntityRepository;
class CustomersRepo extends EntityRepository {} Products Entity<?php
namespace examplemodel;
use Doctrine\ORM\Mapping as ORM;
/**
* Products
*
* @ORM\Table(name="products", indexes={@ORM\Index(name="FK_type_products_id_23021641451650_idx", columns={"type_product_id"}), @ORM\Index(name="FK_customers_id_651016516100456_idx", columns={"customer_id"})})
* @ORM\Entity(repositoryClass="examplemodel\ProductsRepo")
*/
class Products
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="price", type="decimal", precision=10, scale=2, nullable=false)
*/
private $price;
/**
* @var \examplemodel\Customers
*
* @ORM\ManyToOne(targetEntity="examplemodel\Customers")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
* })
*/
private $customer;
/**
* @var \examplemodel\TypeProducts
*
* @ORM\ManyToOne(targetEntity="examplemodel\TypeProducts")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="type_product_id", referencedColumnName="id")
* })
*/
private $typeProduct;
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set price.
*
* @param string $price
*
* @return Products
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price.
*
* @return string
*/
public function getPrice()
{
return $this->price;
}
/**
* Set customer.
*
* @param \examplemodel\Customers|null $customer
*
* @return Products
*/
public function setCustomer(\examplemodel\Customers $customer = null)
{
$this->customer = $customer;
return $this;
}
/**
* Get customer.
*
* @return \examplemodel\Customers|null
*/
public function getCustomer()
{
return $this->customer;
}
/**
* Set typeProduct.
*
* @param \examplemodel\TypeProducts|null $typeProduct
*
* @return Products
*/
public function setTypeProduct(\examplemodel\TypeProducts $typeProduct = null)
{
$this->typeProduct = $typeProduct;
return $this;
}
/**
* Get typeProduct.
*
* @return \examplemodel\TypeProducts|null
*/
public function getTypeProduct()
{
return $this->typeProduct;
}
} Products Repository<?php
namespace examplemodel;
use Doctrine\ORM\EntityRepository;
class ProductsRepo extends EntityRepository {} TypeProducts Entity<?php
namespace examplemodel;
use Doctrine\ORM\Mapping as ORM;
/**
* TypeProducts
*
* @ORM\Table(name="type_products")
* @ORM\Entity(repositoryClass="examplemodel\TypeProductsRepo")
*/
class TypeProducts
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="code", type="string", length=20, nullable=false)
*/
private $code;
/**
* @var string
*
* @ORM\Column(name="lib", type="string", length=100, nullable=false)
*/
private $lib;
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set code.
*
* @param string $code
*
* @return TypeProducts
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* Get code.
*
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* Set lib.
*
* @param string $lib
*
* @return TypeProducts
*/
public function setLib($lib)
{
$this->lib = $lib;
return $this;
}
/**
* Get lib.
*
* @return string
*/
public function getLib()
{
return $this->lib;
}
} TypeProducts Repository<?php
namespace examplemodel;
use Doctrine\ORM\EntityRepository;
class TypeProductsRepo extends EntityRepository {} Generated proxysCustomers Proxy<?php
namespace Proxies\__CG__\examplemodel;
/**
* DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR
*/
class Customers extends \examplemodel\Customers implements \Doctrine\ORM\Proxy\Proxy
{
/**
* @var \Closure the callback responsible for loading properties in the proxy object. This callback is called with
* three parameters, being respectively the proxy object to be initialized, the method that triggered the
* initialization process and an array of ordered parameters that were passed to that method.
*
* @see \Doctrine\Common\Proxy\Proxy::__setInitializer
*/
public $__initializer__;
/**
* @var \Closure the callback responsible of loading properties that need to be copied in the cloned object
*
* @see \Doctrine\Common\Proxy\Proxy::__setCloner
*/
public $__cloner__;
/**
* @var boolean flag indicating if this object was already initialized
*
* @see \Doctrine\Persistence\Proxy::__isInitialized
*/
public $__isInitialized__ = false;
/**
* @var array<string, null> properties to be lazy loaded, indexed by property name
*/
public static $lazyPropertiesNames = array (
);
/**
* @var array<string, mixed> default values of properties to be lazy loaded, with keys being the property names
*
* @see \Doctrine\Common\Proxy\Proxy::__getLazyProperties
*/
public static $lazyPropertiesDefaults = array (
);
public function __construct(?\Closure $initializer = null, ?\Closure $cloner = null)
{
$this->__initializer__ = $initializer;
$this->__cloner__ = $cloner;
}
/**
*
* @return array
*/
public function __sleep()
{
if ($this->__isInitialized__) {
return ['__isInitialized__', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'id', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'name', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'address', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'addressExtra', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'city', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'postalCode'];
}
return ['__isInitialized__', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'id', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'name', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'address', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'addressExtra', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'city', '' . "\0" . 'examplemodel\\Customers' . "\0" . 'postalCode'];
}
/**
*
*/
public function __wakeup()
{
if ( ! $this->__isInitialized__) {
$this->__initializer__ = function (Customers $proxy) {
$proxy->__setInitializer(null);
$proxy->__setCloner(null);
$existingProperties = get_object_vars($proxy);
foreach ($proxy::$lazyPropertiesDefaults as $property => $defaultValue) {
if ( ! array_key_exists($property, $existingProperties)) {
$proxy->$property = $defaultValue;
}
}
};
}
}
/**
*
*/
public function __clone()
{
$this->__cloner__ && $this->__cloner__->__invoke($this, '__clone', []);
}
/**
* Forces initialization of the proxy
*/
public function __load()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, '__load', []);
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
*/
public function __isInitialized()
{
return $this->__isInitialized__;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
*/
public function __setInitialized($initialized)
{
$this->__isInitialized__ = $initialized;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
*/
public function __setInitializer(\Closure $initializer = null)
{
$this->__initializer__ = $initializer;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
*/
public function __getInitializer()
{
return $this->__initializer__;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
*/
public function __setCloner(\Closure $cloner = null)
{
$this->__cloner__ = $cloner;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific cloning logic
*/
public function __getCloner()
{
return $this->__cloner__;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
* @deprecated no longer in use - generated code now relies on internal components rather than generated public API
* @static
*/
public function __getLazyProperties()
{
return self::$lazyPropertiesDefaults;
}
/**
* {@inheritDoc}
*/
public function getId()
{
if ($this->__isInitialized__ === false) {
return (int) parent::getId();
}
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', []);
return parent::getId();
}
/**
* {@inheritDoc}
*/
public function setName($name = NULL)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'setName', [$name]);
return parent::setName($name);
}
/**
* {@inheritDoc}
*/
public function getName()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getName', []);
return parent::getName();
}
/**
* {@inheritDoc}
*/
public function setAddress($address = NULL)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'setAddress', [$address]);
return parent::setAddress($address);
}
/**
* {@inheritDoc}
*/
public function getAddress()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getAddress', []);
return parent::getAddress();
}
/**
* {@inheritDoc}
*/
public function setAddressExtra($addressExtra = NULL)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'setAddressExtra', [$addressExtra]);
return parent::setAddressExtra($addressExtra);
}
/**
* {@inheritDoc}
*/
public function getAddressExtra()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getAddressExtra', []);
return parent::getAddressExtra();
}
/**
* {@inheritDoc}
*/
public function setCity($city = NULL)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'setCity', [$city]);
return parent::setCity($city);
}
/**
* {@inheritDoc}
*/
public function getCity()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getCity', []);
return parent::getCity();
}
/**
* {@inheritDoc}
*/
public function setPostalCode($postalCode = NULL)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'setPostalCode', [$postalCode]);
return parent::setPostalCode($postalCode);
}
/**
* {@inheritDoc}
*/
public function getPostalCode()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getPostalCode', []);
return parent::getPostalCode();
}
} TypeProducts Proxy<?php
namespace Proxies\__CG__\examplemodel;
/**
* DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR
*/
class TypeProducts extends \examplemodel\TypeProducts implements \Doctrine\ORM\Proxy\Proxy
{
/**
* @var \Closure the callback responsible for loading properties in the proxy object. This callback is called with
* three parameters, being respectively the proxy object to be initialized, the method that triggered the
* initialization process and an array of ordered parameters that were passed to that method.
*
* @see \Doctrine\Common\Proxy\Proxy::__setInitializer
*/
public $__initializer__;
/**
* @var \Closure the callback responsible of loading properties that need to be copied in the cloned object
*
* @see \Doctrine\Common\Proxy\Proxy::__setCloner
*/
public $__cloner__;
/**
* @var boolean flag indicating if this object was already initialized
*
* @see \Doctrine\Persistence\Proxy::__isInitialized
*/
public $__isInitialized__ = false;
/**
* @var array<string, null> properties to be lazy loaded, indexed by property name
*/
public static $lazyPropertiesNames = array (
);
/**
* @var array<string, mixed> default values of properties to be lazy loaded, with keys being the property names
*
* @see \Doctrine\Common\Proxy\Proxy::__getLazyProperties
*/
public static $lazyPropertiesDefaults = array (
);
public function __construct(?\Closure $initializer = null, ?\Closure $cloner = null)
{
$this->__initializer__ = $initializer;
$this->__cloner__ = $cloner;
}
/**
*
* @return array
*/
public function __sleep()
{
if ($this->__isInitialized__) {
return ['__isInitialized__', '' . "\0" . 'examplemodel\\TypeProducts' . "\0" . 'id', '' . "\0" . 'examplemodel\\TypeProducts' . "\0" . 'code', '' . "\0" . 'examplemodel\\TypeProducts' . "\0" . 'lib'];
}
return ['__isInitialized__', '' . "\0" . 'examplemodel\\TypeProducts' . "\0" . 'id', '' . "\0" . 'examplemodel\\TypeProducts' . "\0" . 'code', '' . "\0" . 'examplemodel\\TypeProducts' . "\0" . 'lib'];
}
/**
*
*/
public function __wakeup()
{
if ( ! $this->__isInitialized__) {
$this->__initializer__ = function (TypeProducts $proxy) {
$proxy->__setInitializer(null);
$proxy->__setCloner(null);
$existingProperties = get_object_vars($proxy);
foreach ($proxy::$lazyPropertiesDefaults as $property => $defaultValue) {
if ( ! array_key_exists($property, $existingProperties)) {
$proxy->$property = $defaultValue;
}
}
};
}
}
/**
*
*/
public function __clone()
{
$this->__cloner__ && $this->__cloner__->__invoke($this, '__clone', []);
}
/**
* Forces initialization of the proxy
*/
public function __load()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, '__load', []);
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
*/
public function __isInitialized()
{
return $this->__isInitialized__;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
*/
public function __setInitialized($initialized)
{
$this->__isInitialized__ = $initialized;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
*/
public function __setInitializer(\Closure $initializer = null)
{
$this->__initializer__ = $initializer;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
*/
public function __getInitializer()
{
return $this->__initializer__;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
*/
public function __setCloner(\Closure $cloner = null)
{
$this->__cloner__ = $cloner;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific cloning logic
*/
public function __getCloner()
{
return $this->__cloner__;
}
/**
* {@inheritDoc}
* @internal generated method: use only when explicitly handling proxy specific loading logic
* @deprecated no longer in use - generated code now relies on internal components rather than generated public API
* @static
*/
public function __getLazyProperties()
{
return self::$lazyPropertiesDefaults;
}
/**
* {@inheritDoc}
*/
public function getId()
{
if ($this->__isInitialized__ === false) {
return (int) parent::getId();
}
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', []);
return parent::getId();
}
/**
* {@inheritDoc}
*/
public function setCode($code)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'setCode', [$code]);
return parent::setCode($code);
}
/**
* {@inheritDoc}
*/
public function getCode()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getCode', []);
return parent::getCode();
}
/**
* {@inheritDoc}
*/
public function setLib($lib)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'setLib', [$lib]);
return parent::setLib($lib);
}
/**
* {@inheritDoc}
*/
public function getLib()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getLib', []);
return parent::getLib();
}
} ErrorThe error Notice: Accessing static property Proxies_CG_\examplemodel\Customers::$lazyPropertiesNames as non static occured when I try to serialize the entities collection in Test.php |
Same issue here after updating |
Same issue here. Downgrade to |
I have no urgency on my side for the moment. |
yes, downgrading is the solution for now: |
Same error after updating to doctrine 2.7.3. -> Downgrade to 2.7.2. |
can you please try #1210 ? |
I've got expected result string(461) "[{"id":1,"price":"100.00","customer":{"id":1,"name":"Customer 1","address":"Address 1","address_extra":"Address extra 1","city":"City 1","postal_code":"75001"},"type_product":{"id":1,"code":"typeProducts1","lib":"Type product 1"}},{"id":2,"price":"200.00","customer":{"id":2,"name":"Customer 2","address":"Address 2","address_extra":"Address extra 2","city":"City 2","postal_code":"75002"},"type_product":{"id":2,"code":"typeProducts2","lib":"Type product 2"}}]" Good news! |
Same issue with Doctrine 2.8.4. All models serialize normally, except one. If I ignore this notice, serialized model will look like this
Model looks like this:
|
Since orm/doctrine update to 2.7.3 I've got this error (issue title) when I try to serialize an collection of entities "products" get with Doctrine.
Steps required to reproduce the problem
Expected Result (get with orm/doctrine 2.7.2)
In attachment
Actual Result
Archive.zip
The text was updated successfully, but these errors were encountered: