-
Notifications
You must be signed in to change notification settings - Fork 330
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
Base::unique
contains null while type says it does not
#313
Comments
What is the codesnippet to reproduce behaviour that is not expected. It is not initialized which means initially it is null? |
Yes, how could it be something else? final class Ooof extends Base
{
public function readUnique() : UniqueGenerator
{
return $this->unique;
}
}
$ooof = new Ooof(new Generator());
$ooof->readUnique(); // 🎶 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 1 week if no further activity occurs. Thank you for your contributions. |
Is the the full code snippet, @simPod ? |
@bramceulemans yes I guess? What are you asking exactly? |
Where is your constructor, your field assignment to |
Those are your classes as stated in the issue summary use Faker\Generator;
use Faker\Provider\Base;
use Faker\UniqueGenerator;
final class Ooof extends Base
{
public function readUnique() : UniqueGenerator
{
return $this->unique;
}
}
$ooof = new Ooof(new Generator());
$ooof->readUnique(); // 🎶 |
You are missing the constructor in your In order to initialize the |
If there's missing constructor, Either the |
I do not think we can do an easy fix here without it being a breaking change. Since we have a 2.x roadmap we can not just push these breaking changes (since this class is not final). So i think we should live with it for now |
I've created the issue to track the bug so others who encounter it as well can subscribe. You've closed my PR that fixes it already. So the version&roadmap this should be fixed in is your decision ofc. |
Yeah that is fine. In the future these will be final so we can control it a bit better |
I'm not sure that changing a phpdoc block would cause any breaking changes? |
It will not but initialising it as null will. At this point it has no value. The main issue is that it can cause an error that the value is used before initialising. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 1 week if no further activity occurs. Thank you for your contributions. |
387 |
I am closing this since this can not be fixed without a breaking change we do not allow at this point (see contribution guide). For Faker 2.x we will take this into account. Probably those classes will be final to start with so that this can not be extended and only decorated or something like that. |
Summary
Base::unique
property is not initialized in constructor and its type does not allownull
value.Though, the
null
value is there so the type is wrong and it's a bug.Versions
fakerphp/faker
Self-enclosed code snippet for reproduction
See #309 on how to fix the bug
The text was updated successfully, but these errors were encountered: