Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
May 15, 2015
Merged

Add PHP7 compatible versions for the Null/True/False constraints as they are reserved words in PHP7 #14228

merged 1 commit into from
May 15, 2015

Conversation

stefanruijsenaars
Copy link
Contributor

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

@stefanruijsenaars
Copy link
Contributor Author

We can actually provide the deprecated classes through a class_alias...

@Tobion
Copy link
Contributor

Tobion commented Apr 6, 2015

You missed to rename the file NullValidatorTest.php

{
public $message = 'This value should be null.';
}
class_alias('NullConstraint', 'Null');
Copy link
Member

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

Copy link
Member

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');

@nicolas-grekas
Copy link
Member

You should do the False and True constraints in the same PR I believe

@@ -1,6 +1,11 @@
CHANGELOG
=========

New version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.3.28

@nicolas-grekas
Copy link
Member

Do we really want to do that on 2.3? Deprecations are usually forbidden on 2.3.
I'd personally be fine with having PHP7 being fully supported with 2.7 only.

@GromNaN
Copy link
Member

GromNaN commented Apr 6, 2015

About the new class name. What about IsNull instead ? That way we can write Assert\IsNull.

@Tobion
Copy link
Contributor

Tobion commented Apr 6, 2015

We don't deprecate things in maintenance branches. This must be done in 2.7

@fabpot
Copy link
Member

fabpot commented Apr 6, 2015

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?

@wouterj
Copy link
Member

wouterj commented Apr 6, 2015

What about Nil and NotNil?

@stefanruijsenaars
Copy link
Contributor Author

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:
NotNull: NotNull (*as it's not a reserved word) / NotNil / IsNotNull / NotNullConstraint
Null: Nil / IsNull / NullConstraint
True: Truthy / IsTrue / TrueConstraint
False: Falsy / IsFalse / FalseConstraint

@sstok
Copy link
Contributor

sstok commented Apr 6, 2015

I would vote for isNull as its descriptive and consistent with isTrue.

@stefanruijsenaars
Copy link
Contributor Author

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.

@dosten
Copy link
Contributor

dosten commented Apr 6, 2015

@wouterj 👍 Also Truthy and Falsy. What do you think?

@stefanruijsenaars
Copy link
Contributor Author

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');
Copy link
Member

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

@stof
Copy link
Member

stof commented Apr 8, 2015

The NullValidator needs to be deprecated too

@stefanruijsenaars
Copy link
Contributor Author

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) {
Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should. For consistency.

@stof
Copy link
Member

stof commented Apr 21, 2015

@stefanruijsenaars the comment from @nicolas-grekas in #14228 (comment) has not been taken into account

@stof
Copy link
Member

stof commented Apr 21, 2015

@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');
Copy link
Member

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

Copy link
Contributor

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?

@Tobion
Copy link
Contributor

Tobion commented Apr 22, 2015

The trigger_error calls must be added. Oh this is for 2.3. Then these calls should be added in 2.7 i guess.

@Tobion
Copy link
Contributor

Tobion commented Apr 22, 2015

And the same approach should be done for False and True.

@stefanruijsenaars
Copy link
Contributor Author

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...

@nicolas-grekas
Copy link
Member

Is it possible that someone has type hinted Constraints\Null or Constraints\NullValidator (same question for False/True?)
Because the new classes do not pass the deprecated hints, which is a BC break.
To make it pass, we must make IsNullValidator extend the deprecated NullValidator.
We must also alias Null when loading IsNull, and load IsNull from Null.php using class_exists (I know, I said the opposite yesterday, sorry for the mistake...)

}

/**
* @dataProvider legacyGuessRequiredProvider
Copy link
Member

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

@stefanruijsenaars
Copy link
Contributor Author

The checks seems stuck, can we re-queue this somehow?

*/
public function testLegacyGuessRequired()
{
if (PHP_VERSION_ID >= 70000) {
Copy link
Member

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

@Berdir
Copy link
Contributor

Berdir commented May 11, 2015

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.

@nicolas-grekas
Copy link
Member

ping @symfony/deciders

/**
* @author Bernhard Schussek <[email protected]>
*
* @api
*
* @deprecated Deprecated since version 2.3.28, to be removed in 3.0. Use
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

together with trigger_errors

Copy link
Contributor Author

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.

Copy link

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.

@LionsAd
Copy link

LionsAd commented May 13, 2015

So we probably need a 2.7 PR as well?

@nicolas-grekas
Copy link
Member

@stefanruijsenaars can you please remove any comment telling about deprecation (in the patch but also in the PR title/description)?
We are going to consider this as a pure bug fix on 2.3, and we will make an other PR on 2.7 to add the deprecation back after the merge.

@stefanruijsenaars
Copy link
Contributor Author

Done

@stefanruijsenaars stefanruijsenaars changed the title Deprecate Null/True/False constraints as they are reserved words in PHP7 Add PHP7 compatible versions for the Null/True/False constraints as they are reserved words in PHP7 May 13, 2015
------

* 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)
Copy link
Member

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)

@nicolas-grekas
Copy link
Member

Looking at the tests, you need to patch one more file:
https://github.com/stefanruijsenaars/symfony/blob/php7-nullconstraint/src/Symfony/Component/Form/composer.json#L28
should be:
"symfony/validator": "~2.3.0,>=2.3.29",

@xabbuh
Copy link
Member

xabbuh commented May 13, 2015

Why not using ~2.3.29 instead then?

@nicolas-grekas
Copy link
Member

@xabbuh indeed

@Tobion
Copy link
Contributor

Tobion commented May 13, 2015

👍

…IsNull, IsTrue, IsFalse) and related validators (IsNullValidator, IsTrueValidator, IsFalseValidator)
@stof
Copy link
Member

stof commented May 15, 2015

👍

@stof
Copy link
Member

stof commented May 15, 2015

Thanks for your work on this @stefanruijsenaars.

@stof stof merged commit 44edbdf into symfony:2.3 May 15, 2015
stof added a commit that referenced this pull request May 15, 2015
…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)
@stefanruijsenaars
Copy link
Contributor Author

Do we have a 2.7 PR for this yet?

2015-05-15 11:26 GMT+02:00 Christophe Coevoet [email protected]:

Merged #14228 #14228.


Reply to this email directly or view it on GitHub
#14228 (comment).

@nicolas-grekas
Copy link
Member

@stefanruijsenaars it is already in 2.7, check the git log

xezpeleta added a commit to elkarbackup/elkarbackup that referenced this pull request Sep 27, 2016
konandrum added a commit to IDCI-Consulting/ExtraFormBundle that referenced this pull request Jan 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.