8000 Support for PHP 7.1 nullables · Issue #19771 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Support for PHP 7.1 nullables #19771

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

Closed
mvrhov opened this issue Aug 29, 2016 · 5 comments
Closed

Support for PHP 7.1 nullables #19771

mvrhov opened this issue Aug 29, 2016 · 5 comments
Labels

Comments

@mvrhov
Copy link
mvrhov commented Aug 29, 2016

This is an excerpt from the #19677.

The upcoming PHP 7.1 will add support for nullable types. So the function declarations in php 7.1 won't need a default null parameter e.g \StdClass $foo = null but could be written as ?\StdClass $fool.

I'm assuming that there are a lot of argument resolvers e.g controller argument resolver, DI, .. inside a Symfony which would complain or throw an exception on new declaration. The new version will be released around the symfony 3.2 release so this would fit nicely together.

@linaori
Copy link
Contributor
linaori commented Aug 29, 2016

Right now the builds are being tested on 7.1 so it's at least backwards compatible for now. I'll see if I can add a test-case for 7.1.

@dunglas
Copy link
Member
dunglas commented Sep 1, 2016

There is probably some work to do in the PropertyInfo component to support this new feature.

@linaori
Copy link
Contributor
linaori commented Sep 1, 2016

I could have a look at it but that's a bit beyond my expertise ^^

@dunglas
Copy link
Member
dunglas commented Sep 1, 2016

IIUC, it doesn't change the reflection API and ReflectionParameter::allowsNull() will return true if null is allowed using the new notation. So we don't have to change anything.

@linaori
Copy link
Contributor
linaori commented Sep 1, 2016

Previously it would return true if the signature had = null as default value so it might have some behavioral changes when called manually: (?string $value), (?string $value= 'value')

fabpot added a commit 8000 that referenced this issue Sep 14, 2016
…low (iltar)

This PR was squashed before being merged into the 3.1 branch (closes #19784).

Discussion
----------

[HttpKernel] Fixed the nullable support for php 7.1 and below

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19771
| License       | MIT
| Doc PR        | ~

This PR gives support for for the new php 7.1 and will only work in beta3 or higher. I've had to backport the support to 3.1 because I consider this a bug that it won't work, even though 3.1 won't be supported for much longer. ~~The deprecation I've added in the `ArgumentMetadata` should not be triggered as all framework cases create it with the argument. Just for developers who for some reason implemented this manually, I've added the deprecation.~~

~~*If needed, I can re-open this against 3.2 and leave 3.1  "broken"*~~

On 7.1 lower than beta3 this will happen but shouldn't affect any higher versions (I hope).
```
There was 1 failure:

1) Symfony\Component\HttpKernel\Tests\ControllerMetadata\ArgumentMetadataFactoryTest::testNullableTypesSignature
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata Object (...)
     1 => Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata Object (
         'name' => 'bar'
-        'type' => 'stdClass'
+        'type' => 'Symfony\Component\HttpKernel\Tests\Fixtures\Controller\stdClass'
         'isVariadic' => false
         'hasDefaultValue' => false
         'defaultValue' => null
         'isNullable' => true
     )
     2 => Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata Object (...)
 )

/home/ivanderberg/projects/symfony/src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php:123
```

Commits
-------

4a1ab6d [HttpKernel] Fixed the nullable support for php 7.1 and below
@fabpot fabpot closed this as completed Sep 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants
0