-
Notifications
You must be signed in to change notification settings - Fork 241
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
optional array parameter causes incompatible prototype generation #368
Comments
Probably significant that |
Yeah that's indeed probably more significant than the array type |
Hmmm maybe my signature is stupid... I mean if I pass null, my code doesn't work, I think. |
Can you show the actual method signature of your concrete class? |
public static function fromNative(
string $contentId,
string $originalTitle,
string $workType,
string $birthday,
string $durationSpec,
string $countryOfOrigin,
string $language,
string $title,
?string $identifier = null,
?array $alternateIdentifiers = []
): self { I now realise it is indeed stupid to do that, but it's valid php, so... should work. |
So possibly https://github.com/phpspec/prophecy/blob/master/src/Prophecy/Doubler/Generator/ClassCodeGenerator.php#L98 is receiving the wrong value from |
Some reason being that the default value isn't null |
See #377, I think it resolves the issue |
Just for the record: We have an class in zend-expressive-router where we are updating it to have the following signature: public static function fromRouteFailure(?array $allowedMethods = []) : self This particular change triggers the error reported above. We have a reason for the defaults:
We could potentially alter this to make the value required. That said, I don't see this as an exceptional situation; I can think of a few other cases (such as a nullable string with a default argument) where this might be of use. The problem only occurs once you're testing on PHP 7.1 and above, which is why we just noticed it (as we're just now updating the library to depend on 7.1+). I can verify #377 fixes the issue, and would love to see a bugfix release we could pin against that includes it! 😁 |
booleans also don't work public function findOneActiveBySystemName(string $system_name, bool $visibility = true): ProductInterface
public function findOneActiveBySystemName(string $system_name, ?bool $visibility = true): ProductInterface |
same for ints: |
Hotfix #368: Optional nullable array parameter with not null default value
Raw error message I get when running phpspec:
Diff between signatures
Notice how things are ok for the
$identifier
parameter, which is of type string.The text was updated successfully, but these errors were encountered: