Comments (9)
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.
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.
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.
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.
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.
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.
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.
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.
Can we close this issue? I don't think it's actionable for us.
from instantiator.
Related Issues (20)
- Extension HOT 2
- missing shebang in .travis.install.sh HOT 2
- Enable CI services HOT 1
- What about to add the capability to set properties with given set of values? HOT 9
- Unable to instanciate Symfony\Component\HttpFoundation\File\File HOT 7
- Verify compatibility with PHP 5.6.0 (stable, once released) HOT 3
- version 1.1.0 broke phpunit on PHP 5.4 ~ PHP 5.6 HOT 7
- Dependency problem HOT 4
- Strange fatal error in PHP 7.1 due to void return hint HOT 2
- Minimum PHP version change in minor is breaking dependents HOT 21
- PHP 7.1 in composer HOT 1
- doctrine/instantiator 1.0.1 requires php ~5.3 -> your PHP version (7.1.8) does not satisfy that HOT 4
- Requirement of PHP7.1 breaking other packages HOT 4
- Can't instantiate final class extending ArrayIterator HOT 18
- ext requirements HOT 1
- version 1.1.0 is breaking PHP < 7.1 HOT 4
- Add documentation
- Add in the README the meaning HOT 7
- Instantiator attempts to clone classes that are not cloneable HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from instantiator.