Giter VIP home page Giter VIP logo

Comments (9)

jvasseur avatar jvasseur commented on June 17, 2024 2

This is because your promoted property example is equivalent to

<?php
class Foo {
    private ?string $bar;
    public function __construct(?string $bar = null) {
        $this->bar = $bar;
    }
}

thus the property ends up without a default value and since Doctrine skip the constructor when loading objects from the database the property isn't initialized.

from instantiator.

jvasseur avatar jvasseur commented on June 17, 2024 1

Well in most case it wouldn't be a problem since the constructor would set the property and thus eliminate the need to set a default value on it. It's only a problem in doctrine where constructor is skipped during object creation.

from instantiator.

garak avatar garak commented on June 17, 2024

thus the property ends up without a default value and since Doctrine skip the constructor when loading objects from the database the property isn't initialized.

Are you sure? That doesn't make sense at all (for PHP)

from instantiator.

greg0ire avatar greg0ire commented on June 17, 2024

See https://www.doctrine-project.org/projects/doctrine-instantiator/en/latest/index.html
Maybe a test case should be added to that project?

from instantiator.

jvasseur avatar jvasseur commented on June 17, 2024

thus the property ends up without a default value and since Doctrine skip the constructor when loading objects from the database the property isn't initialized.

Are you sure? That doesn't make sense at all (for PHP)

This makes a lot of sens if you want users of the ORM to do what they want in the constructor, this could be requiring arguments to be passed to the constructor (were the ORM wouldn't know what to pass) or even triggering side effects in the constructor.

from instantiator.

garak avatar garak commented on June 17, 2024

I mean: it doesn't make sense that PHP disallow putting a default value in a (promoted) property when such null value is required.

from instantiator.

jvasseur avatar jvasseur commented on June 17, 2024

Well, desugaring the default value as the argument default value instead of the property default value makes sense since it allows omitting it when calling the constructor.

The default value could be desugared as a default value in both the property and the constructor but the RFC explains why this could cause problems in the future.

from instantiator.

garak avatar garak commented on June 17, 2024

But I can't understand why they didn't consider the special case of nullable variables, where null must be a default.
Anyway, if I understand correctly, the only solution here is avoiding promotion.

from instantiator.

derrabus avatar derrabus commented on June 17, 2024

Can we close this issue? I don't think it's actionable for us.

from instantiator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.