-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add PHP7 compatible versions for the Null/True/False constraints as they are reserved words in PHP7 #14228
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
Conversation
We can actually provide the deprecated classes through a class_alias... |
You missed to rename the file |
{ | ||
public $message = 'This value should be null.'; | ||
} | ||
class_alias('NullConstraint', 'Null'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The full namespace must be provided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to keep type hints working (... instanceof Null
), this class_alias should be moved at the end of NullConstraint.php, and this very line should be replaced by a class_exists('Symfony\Component\Validator\Constraints\NullConstraints');
You should do the False and True constraints in the same PR I believe |
@@ -1,6 +1,11 @@ | |||
CHANGELOG | |||
========= | |||
|
|||
New version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.3.28
Do we really want to do that on 2.3? Deprecations are usually forbidden on 2.3. |
About the new class name. What about |
We don't deprecate things in maintenance branches. This must be done in 2.7 |
The only reason to add those deprecation in 2.3 would be to allow 2.3 to be PHP 7 compatible. Is that what we want? |
What about |
If 2.3 is still supported by the time PHP 7 comes out it would make sense to put this in 2.3, per #14086 we're quite close to being compatible so if we drop PHP 7 support it shouldn't be just because we're deprecating a few constraints :) Does anyone have any further ideas about new names for the following constraints, I've already seen the following: |
I would vote for isNull as its descriptive and consistent with isTrue. |
I will add the new True and False constraints to this PR as well once the Null constraint has been properly reviewed and once there's consensus on the new naming. Just FYI, this is currently causing a test failure on Drupal 8/PHP 7 as it uses the Null constraint in a test. |
@wouterj 👍 Also |
Thanks all, just to be clear, what are we renaming these constraints to? |
public $message = 'This value should be null.'; | ||
} | ||
|
||
class_alias('Symfony\Component\Validator\Constraints\NullConstraint', 'Symfony\Component\Validator\Constraints\Null'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line should be skipped on PHP7, otherwise the issue is not solved
The NullValidator needs to be deprecated too |
Does this seem ready? What still needs to happen here? |
public $message = 'This value should be null.'; | ||
} | ||
|
||
if (version_compare(PHP_VERSION, '7.0.0-dev') < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use PHP_VERSION_ID < 70000
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should. For consistency.
@stefanruijsenaars the comment from @nicolas-grekas in #14228 (comment) has not been taken into account |
@stefanruijsenaars note that your commits are not associated to your github account (the email used when committing is not known by github). You might want to change this |
{ | ||
public $message = 'This value should be null.'; | ||
} | ||
class_exists('Symfony\Component\Validator\Constraints\IsNull'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @stof above: this should be replaced by class_alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree as well. @stefanruijsenaars could you do this change?
The |
And the same approach should be done for |
As soon as I have confirmation that this looks good as far as Null is concerned I can do the same for False and True... |
Is it possible that someone has type hinted |
} | ||
|
||
/** | ||
* @dataProvider legacyGuessRequiredProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the data provider
The checks seems stuck, can we re-queue this somehow? |
*/ | ||
public function testLegacyGuessRequired() | ||
{ | ||
if (PHP_VERSION_ID >= 70000) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two indentation spaces missing for the whole method
I wasn't able to reproduce the recursion that travis reports. The validator tests are running through for me on php7 (PHP 7.0.0-dev (cli) (built: May 6 2015 00:41:14)). However, I have a lot of test fails, all because the string representation of a DateTime object is somehow different, it expects 'Jan 1, 2000, 12:00 AM' but actually gets 'Jan 1, 2000 12:00 AM' (note the missing , after the year). But that seems like a different problem and could be environment specific. |
ping @symfony/deciders |
/** | ||
* @author Bernhard Schussek <[email protected]> | ||
* | ||
* @api | ||
* | ||
* @deprecated Deprecated since version 2.3.28, to be removed in 3.0. Use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not add deprecations in patch versions. So this comment should should only be added in 2.7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
together with trigger_errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So trigger_errors in 2.7 only?
This discussion had appeared earlier in this thread as well, I think back then it was decided to make an exception? Though @fabpot did mention the deprecations would only be necessary if we wanted to make the branch PHP7 compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just talked with @fabpot in person and yes the deprecation and trigger_error is only in 2.7.
2.3 will be PHP 7 compatible for Symfony for out-of-the-box, but we won't prevent others from still using the old constraints, etc. (and such make it PHP 7 incompatible)
That way 2.3 is compatible out-of-the-box for Drupal + PHP 7, but you could still shoot yourself in the foot with a custom extension.
In 2.7 then it will start with deprecation notices.
So we probably need a 2.7 PR as well? |
@stefanruijsenaars can you please remove any comment telling about deprecation (in the patch but also in the PR title/description)? |
Done |
------ | ||
|
||
* added PHP7-compatible versions for the constraints Null, True and False (IsNull, IsTrue, IsFalse) | ||
* added PHP7-compatible versions for the constraint validators NullValidator, TrueValidator and FalseValidator (IsNullValidator, IsTrueValidator, IsFalseValidator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose a single line:
- fixed compatibility with PHP7 and up by introducing new constraints (IsNull, IsTrue, IsFalse) and related validators (IsNullValidator, IsTrueValidator, IsFalseValidator)
Looking at the tests, you need to patch one more file: |
Why not using |
@xabbuh indeed |
👍 |
…IsNull, IsTrue, IsFalse) and related validators (IsNullValidator, IsTrueValidator, IsFalseValidator)
👍 |
Thanks for your work on this @stefanruijsenaars. |
…straints as they are reserved words in PHP7 (stefan.r) This PR was merged into the 2.3 branch. Discussion ---------- Add PHP7 compatible versions for the Null/True/False constraints as they are reserved words in PHP7 | Q | A | ------------- | --- | Bug fix? | PHP7 compatibility | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | N/A | Fixed tickets | N/A - helps towards #14086 | License | MIT Null, True and False are reserved words in PHP7: https://wiki.php.net/rfc/reserve_more_types_in_php_7 Commits ------- 44edbdf Fixed compatibility with PHP7 and up by introducing new constraints (IsNull, IsTrue, IsFalse) and related validators (IsNullValidator, IsTrueValidator, IsFalseValidator)
Do we have a 2.7 PR for this yet? 2015-05-15 11:26 GMT+02:00 Christophe Coevoet [email protected]:
|
@stefanruijsenaars it is already in 2.7, check the git log |
Null, True and False are reserved words in PHP7:
https://wiki.php.net/rfc/reserve_more_types_in_php_7