Skip to content

Conversation

@zlodes
Copy link

@zlodes zlodes commented Dec 8, 2020

Related issue:
#43

  • Fixed tests
  • Fixed previous versions support (7.0 - 7.4)

@zlodes zlodes mentioned this pull request Dec 8, 2020
@zlodes zlodes changed the base branch from master to 1.x December 8, 2020 12:30
@zlodes zlodes mentioned this pull request Dec 23, 2020
@zlodes
Copy link
Author

zlodes commented Dec 23, 2020

@rtheunissen Hi!
This PR has trouble with reflection test. It prints that null is allowed for some methods.

Can you help me?

@zlodes zlodes mentioned this pull request Jan 17, 2021
@rtheunissen
Copy link
Contributor

Hi @zlodes, I am taking a look at this now. It feels like yesterday that this issue was opened. Thank you for this work.

@rtheunissen
Copy link
Contributor

This is excellent. What is the reason for the php8-specific tests?

@rtheunissen rtheunissen marked this pull request as ready for review February 9, 2021 03:35
@zlodes
Copy link
Author

zlodes commented Feb 9, 2021

@rtheunissen some PHP8 and 7.4 errors have the different string representation.

And I don't know how to fit it into one test.

@rtheunissen
Copy link
Contributor

@zlodes I'm stuck on these reflection tests. I'm assuming "allow null" is the ? part of nullable type like ?int, but in this case the parameter does not have a type, it is __construct($value, int $precision = DEFAULT_PRECISION) so is that allow null or not? Perhaps 7.4/8 treat this case differently.

@rtheunissen
Copy link
Contributor

I am going to inspect using php --re decimal

@rtheunissen
Copy link
Contributor

Looking at the $value parameter:

PHP 7.4.9
ZEND_ARG_INFO(0, name)
allows_null: false

        Method [ <internal:decimal, ctor> public method __construct ] {

          - Parameters [2] {
            Parameter #0 [ <optional> $value ]
            Parameter #1 [ <optional> int $precision ]
          }
        }

PHP 8.0.9
ZEND_ARG_INFO(0, name)
allows_null: true

        Method [ <internal:decimal, ctor> public method __construct ] {

          - Parameters [2] {
            Parameter #0 [ <optional> $value = <default> ]
            Parameter #1 [ <optional> int $precision = <default> ]
          }
        }
<?php

function testA($value) {}

$a = new ReflectionFunction('testA');

foreach ($a->getParameters() as $param) {
    var_dump($param->allowsNull());
}

^ This shows bool(true) for all versions, so I this should be the reference behavior.

Notice that we mark the parameters optional. In the testA method above the $value parameter is not optional. The only way to make it optional is to give it a type, or set its default to null, and because we have multiple types the only option is to set the default value to 0. I'll try some arginfo combinations in that direction.

@rtheunissen
Copy link
Contributor

It seems that 7.4 does not have the argument info capabilities to make this consistent. I'll create the variation of the test for php8 and if issues about nullable types come up we can evaluate them as bugs then.

@rtheunissen
Copy link
Contributor

I am going to merge this and make some minor changes thereafter. That makes 1.x compatible with PHP 8 which is worth a minor release along with anything else that was merged in the meantime.

@rtheunissen rtheunissen merged commit e175ab5 into php-decimal:1.x Feb 9, 2021
@zlodes
Copy link
Author

zlodes commented Feb 9, 2021

@rtheunissen thank you!
Waiting for the release with PHP8.0 support. ❤️

@carlonicora
Copy link

Hello!

Sorry for pushing, but was curious to see if there is an ETA for the PHP8.0 support to be released.

Thanks A LOT for your work!

@zlodes zlodes deleted the 1.x-php8 branch October 15, 2021 23:15
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.

3 participants