Skip to content
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

Add is_countable under PHP 7.3 #115

Merged
merged 1 commit into from
Apr 25, 2018
Merged

Add is_countable under PHP 7.3 #115

merged 1 commit into from
Apr 25, 2018

Conversation

carusogabriel
Copy link
Contributor

As requested by @nicolas-grekas :)

Waiting for php/php-src#3026

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

thank you :)


if (PHP_VERSION_ID < 70300) {
if (!function_exists('is_countable')) {
function is_countable($s) { return p\Php73::is_countable($s); }
Copy link
Member

Choose a reason for hiding this comment

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

for such a simple implementation, I think we can inline the code a remove the static class (as done on other polyfills AFAIK)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas Sure, gonna do this!

/**
* @author Gabriel Caruso <carusogabriel34@gmail.com>
*
* @covers Symfony\Polyfill\Php73\Php73::<!public>
Copy link
Member

Choose a reason for hiding this comment

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

should be removed in you accept the previous comment (same below)

$this->assertTrue(is_countable([1, 2, 3]));
$this->assertTrue(is_countable(new \ArrayIterator(['foo', 'bar', 'baz'])));
$this->assertTrue(is_countable(new \ArrayIterator()));
$this->assertFalse(is_countable(new \stdClass()));
Copy link
Member

Choose a reason for hiding this comment

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

please add a case with generator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@keradus Is this possible with 5.x tests?

Copy link
Member

Choose a reason for hiding this comment

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

even if not, it shall still be tested

Copy link
Member

@stof stof left a comment

Choose a reason for hiding this comment

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

the root composer.json needs to be updated to add the replace rule for the new package.

"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
Copy link
Member

Choose a reason for hiding this comment

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

should be 1.8 (and we should bump the version in master before merging this), as this is a new feature and so will be a new minor version, not a new patch version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stof I'll just wait for the official merge in php-src, I'll do it :)

@carusogabriel
Copy link
Contributor Author

@nicolas-grekas Should be ready to go 😃

Copy link
Member

@keradus keradus left a comment

Choose a reason for hiding this comment

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

👎

  • Travis is failing (as you used short-array syntax not yet available for 5.3)
  • generator test case shall be added, to ensure polyfill works for it properly
  • tests are suppose to be executed, on different environments, with polyfill (on PHP versions that don't have the feature yet), and without it (using real feature). here, we always run test with a polyfill, never on PHP 7.3, as 7.3 is not part of Travis matrix

for ($i = 1; $i <= 10; ++$i) {
yield $i;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@keradus Is there a way to add generators tests without breaking the build?

Copy link
Member

Choose a reason for hiding this comment

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

the yield code would need to be extracted to dedicated file and loaded conditionally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@keradus Done, thanks.

*/
public function testIsCountable()
{
$this->assertTrue(is_countable(array(1, 2, '3')));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@keradus Fixed the array syntax, thanks.

@keradus
Copy link
Member

keradus commented Mar 12, 2018

looks better with every change @carusogabriel !
(btw, if you would not squash, it would be way easier to review the changes, now one need to read whole diff again and again, instead of just patch - don't worry, squash can be done during merging!)

one last thing - could you extend .travis.yml matrix to contain 7.2 and 7.3 ?

@carusogabriel
Copy link
Contributor Author

carusogabriel commented Mar 12, 2018

@keradus

btw, if you would not squash, it would be way easier to review the changes, now one need to read whole diff again and again, instead of just patch - don't worry, squash can be done during merging!

Sure, thanks for the tip, I always amend my commits, but I'll start to commit and then squash them before merging the PR, thanks!

could you extend .travis.yml matrix to contain 7.2 and 7.3 ?

Sure, pushing these changes ASAP.

@carusogabriel
Copy link
Contributor Author

@keradus There's one remain error in PHP 7.3 that I couldn't figure out how to solve. Maybe we should just add 7.2?

@keradus
Copy link
Member

keradus commented Mar 12, 2018

the feature you are adding has to be tested under 7.3. if not, then we test only "does our polyfill work like we expect", but don't "does our polyfill expectation are same as original implementation".
yet, I agree 7.3 failing is not related to your PR.
sth nice to have for sure, but maybe indeed out of the scope here. nevertheless, adding it (even temporary) to travis matrix has proven that your changes works same as native implementation.

if you ask me, I would be fine with reverting travis changes and do it as separated PR.

@keradus
Copy link
Member

keradus commented Apr 6, 2018

@stof , your request has been already fulfilled, could you please revisit your review ?

In general, missing thing on Travis is related to Mbstring, thus it's not connected with feature introduced by this PR.
Could we make this one released?

@xabbuh xabbuh mentioned this pull request Apr 19, 2018
@@ -50,6 +51,7 @@
"src/Php70/bootstrap.php",
"src/Php71/bootstrap.php",
"src/Php72/bootstrap.php",
"src/Php73/bootstrap.php",
Copy link
Member

Choose a reason for hiding this comment

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

the branch-alias should be updated to 1.8-dev for all composer.json files of the repo

@@ -0,0 +1,19 @@
Copyright (c) 2015-2018 Fabien Potencier
Copy link
Member

Choose a reason for hiding this comment

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

2018 only (not "2015-")


if (PHP_VERSION_ID < 70300) {
if (!function_exists('is_countable')) {
function is_countable($s) {
Copy link
Member

Choose a reason for hiding this comment

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

the function should be on one single line (to make the test suite work as expected)
$s should be renamed by $var I suppose also.

@nicolas-grekas
Copy link
Member

Would you mind adding hrtime() also in the PHP 7.3 polyfill (based on microtime())?

  . Added monotonic timer function hrtime([bool get_as_num]). It returns an
    array of the form [seconds, nanoseconds] with the timestamp starting at
    an unspecified point in the past. If the optional argument is passed as
    true, the return value is an integer on 64-bit systems or float on
    32-bit systems, representing the nanoseconds. The timestamp is not
    adjustable and is not related to wall clock or time of day. The timers
    are available under Linux, FreeBSD, Windows, Mac, SunOS, AIX and their
    derivatives. If no required timers are provided by a corresponding
    platform, the function returns false.

@keradus
Copy link
Member

keradus commented Apr 19, 2018

Could we please add different feature with different PR?
This one is already awaiting for 2.5 months, no need to postpone it even further ;)

@nicolas-grekas
Copy link
Member

Thank you @carusogabriel.

@nicolas-grekas nicolas-grekas merged commit 803a622 into symfony:master Apr 25, 2018
nicolas-grekas added a commit that referenced this pull request Apr 25, 2018
This PR was squashed before being merged into the 1.7-dev branch (closes #115).

Discussion
----------

Add is_countable under PHP 7.3

As requested by @nicolas-grekas :)

Waiting for php/php-src#3026

Commits
-------

803a622 Add is_countable under PHP 7.3
@nicolas-grekas
Copy link
Member

FYI, I removed the nightly line because it failed for unrelated reason, to be fixed in a next PR. hrtime() welcome now.

@carusogabriel carusogabriel deleted the is-countable branch April 25, 2018 15:15
@Majkl578
Copy link

Majkl578 commented Apr 25, 2018

As noted in the commit here: symfony/polyfill-php73@f713942#r28736995
This implementation is incorrect.

This implementation is not correct. There are objects that are countable, but do not implement Countable, for example SimpleXmlElement: https://3v4l.org/IcOMX

Also see https://github.com/php/php-src/pull/3026/files#r170670721.

nicolas-grekas added a commit that referenced this pull request Apr 26, 2018
…t implement \Countable (pierredup)

This PR was merged into the 1.8-dev branch.

Discussion
----------

Update is_countable to include countable objects that doesn't implement \Countable

Some objects are countable but don't implement `Countable` ([#115#issuecomment-384361414](#115 (comment)))

The objects that I could identify that is countable is `ResourceBundle` and `SimpleXmlElement`

Commits
-------

b53929e Update is_countable to include countable objects that doesn't implement \Countable
symfony-splitter pushed a commit to symfony/polyfill-php73 that referenced this pull request Apr 26, 2018
…t implement \Countable (pierredup)

This PR was merged into the 1.8-dev branch.

Discussion
----------

Update is_countable to include countable objects that doesn't implement \Countable

Some objects are countable but don't implement `Countable` ([symfony/polyfill#115#issuecomment-384361414](symfony/polyfill#115 (comment)))

The objects that I could identify that is countable is `ResourceBundle` and `SimpleXmlElement`

Commits
-------

b53929e Update is_countable to include countable objects that doesn't implement \Countable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants