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

PHP8.0 compatibility patch #32

Closed
wants to merge 22 commits into from
Closed

Conversation

Megatherium
Copy link

@Megatherium Megatherium commented Nov 19, 2020

Some of the more common things that needed be fixed were:

  • A lot of times where PHP used to emit a warning (or even nothing) we
    now get Type- and ValueErrors which either need to be prevented by
    intializing or casting variables or catching the error.

  • file_exists will error out if you feed it NULL bytes. This needed to
    be circumvented

  • optional parameters need to come after required params, thus some
    default values had to be removed from method signatures and workarounds
    put in place

  • some reflection methods like isArray have become deprecated and are
    only called conditionally going forward

  • libxml_disable_entity_loader has been deprecated and is only called
    conditionally

@glensc
Copy link
Contributor

glensc commented Nov 19, 2020

Copy link
Contributor

@glensc glensc left a comment

Choose a reason for hiding this comment

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

Dropped some notes, In overall good work!

composer.json Outdated Show resolved Hide resolved
packages/zend-file/library/Zend/File/ClassFileLocator.php Outdated Show resolved Hide resolved
tests/Zend/CodeGenerator/Php/ParameterTest.php Outdated Show resolved Hide resolved
tests/Zend/Date/DateObjectTest.php Outdated Show resolved Hide resolved
tests/Zend/Date/DateObjectTest.php Outdated Show resolved Hide resolved
@Megatherium
Copy link
Author

Finally got around to reworking that history. Let's see how Travis feels about it :)

@Megatherium
Copy link
Author

Everything checks out except for that one thing in Zend_Log_Writer_AbstractTest with PHP5.4 which also only occurs if you run the full suite. All three tests pass if you run that thing manually.

@Megatherium
Copy link
Author

@falkenhawk Do you want me to put a guard in for that specific case so we can have pretty green arrows?

packages/zend-pdf/library/Zend/Pdf/Filter/RunLength.php Outdated Show resolved Hide resolved
tests/Zend/CodeGenerator/Php/ParameterTest.php Outdated Show resolved Hide resolved
Comment on lines -60 to +63
$iterator = $this->stack->getIterator();
$this->assertEquals('Zend_Controller_Action_Helper_Redirector', get_class(current($iterator)));
next($iterator);
$this->assertEquals('Zend_Controller_Action_Helper_ViewRenderer', get_class(current($iterator)));
$iterator = $this->stack->getIterator()->getIterator();
$this->assertEquals('Zend_Controller_Action_Helper_Redirector', get_class($iterator->current()));
$iterator->next();
$this->assertEquals('Zend_Controller_Action_Helper_ViewRenderer', get_class($iterator->current()));
Copy link
Member

Choose a reason for hiding this comment

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

does php8 throw on calling current() / next() on an iterator?

Copy link
Author

Choose a reason for hiding this comment

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

It retuns false and thus get_class throws a TypeError

tests/Zend/Date/DateObjectTest.php Show resolved Hide resolved
Comment on lines +92 to +94
if (stristr($e->getMessage(), 'undefined constant')) {
$this->markTestSkipped();
}
Copy link
Member

Choose a reason for hiding this comment

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

In which case this the db factory throws this undefined constant error? What kind of constants were missing?

Copy link
Author

Choose a reason for hiding this comment

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

DB2 constants

tests/Zend/Filter/HtmlEntitiesTest.php Show resolved Hide resolved
Comment on lines 1767 to +1773
$options['filters'] = array(
array('Digits', array('bar' => 'baz')),
array('Alnum', array('allowWhiteSpace' => true)),
array('Alpha', array('foo')),
);
$this->element->setOptions($options);
$filter = $this->element->getFilter('Digits');
$this->assertTrue($filter instanceof Zend_Filter_Digits);
$filter = $this->element->getFilter('Alnum');
$this->assertTrue($filter instanceof Zend_Filter_Alnum);
Copy link
Member

Choose a reason for hiding this comment

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

the behavior of this tests has changed. Could you comment on why, please?

Copy link
Author

Choose a reason for hiding this comment

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

The behaviour hasn't really changed because the intent of the test is to use an array of arrays in setOptions. What has changed is that PHP8 supports calling functions with named parameters and will throw a Fatal if you try to access a parameter by name that does not exist. Digits::__construct has no param named bar ergo we get a Fatal.

I could add a version switch but that wouldn't make the test any more meaningful.

tests/Zend/Validate/DateTest.php Outdated Show resolved Hide resolved
Comment on lines 55 to +59
} catch (Exception $e) {
$this->assertTrue($e instanceof Zend_Log_Exception);
$this->assertRegExp('/not a stream/i', $e->getMessage());
} catch (TypeError $e) {
$this->assertRegExp('/must be of t/i', $e->getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure about the adjustments here. Were these TypeError, ValueError triggered as regular errors in PHP <8 or were they simply non-errors before and now PHP 8 is more strict? If that's the case, is it okay that PHP8 will throw such errors instead of the php <8 shrug-and-proceed behavior?

Copy link
Author

Choose a reason for hiding this comment

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

Usually where I added Error catches the behaviour in <8 was to emit a warning or fail silently.

Copy link
Member

Choose a reason for hiding this comment

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

Okay I guess it is fine in case of this component - when something is wrong with internals of this stream thing, it should throw

@falkenhawk
Copy link
Member

@falkenhawk Do you want me to put a guard in for that specific case so we can have pretty green arrows?

@Megatherium I will try to run php5.4 test suite locally to see if I can figure out why it fails

@glensc
Copy link
Contributor

glensc commented Dec 6, 2020

#35 created a separate issue, so it can be worked independently of this PR.

Megatherium pushed a commit to Megatherium/zf1 that referenced this pull request Dec 31, 2020
As this branch does not contain the major fixes for PHP8 ( cf.
zf1s#32) the tests will
abort with a fatal. Thus Travis has beeb allowed to fail for PHP8.
@glensc glensc mentioned this pull request Feb 3, 2021
32 tasks
Megatherium pushed a commit to Megatherium/zf1 that referenced this pull request Feb 4, 2021
As this branch does not contain the major fixes for PHP8 ( cf.
zf1s#32) the tests will
abort with a fatal. Thus Travis has beeb allowed to fail for PHP8.
@Megatherium
Copy link
Author

So, next step:

Rebase this to master, add 8.0 to Github actions, disallow failure for 8.0 on Travis.

Correct?

@Megatherium
Copy link
Author

Megatherium commented Feb 5, 2021

I don't really get why that test bails all of the sudden in 5.4. As far as I can tell I haven't touched any file involved in that test. Also that test is supposed to cause an error which PHPUnit should handle... I'm confused.

onlime added a commit to onlime/zf1-future that referenced this pull request Feb 7, 2021
Because the return values of iconv_substr changed in PHP8 calling
Zend_Date::set could lead to TypeError
@glensc
Copy link
Contributor

glensc commented Feb 18, 2021

@falkenhawk @Megatherium seems this is stalled again. Is there any interest, I could cherry-pick commits related from here to separate PRs? So the changeset could be merged individually, not depending on the "big approval".

I need confirmation, so I won't end up doing unwanted work.

@falkenhawk
Copy link
Member

@glensc thanks for stepping up. I believe there is lots of interest, but I guess we all might be constrained by the regular job responsibilities or other stuff. As much as I would like to have it done, I can't merge it yet when there are tests failing. I would also love to jump in and help but I am afraid I can't do at the moment.

Is that failing test due to the issue with iconv the only thing left to be sorted out here? If you have an idea how to fix it then perhaps could you either rebase or merge from master and push a fix? 🙏

Please coordinate with @Megatherium if possible so that work is not doubled, perhaps Alex has some work not pushed yet.

@Megatherium
Copy link
Author

The thing is I believe the test setup and not the code to be wrong. I know this is basically like claiming a compiler bug but iconv is an external resource and I didn't have my little grubby hands anywhere near the failing code.
Same with Zend_Queue_Queue1Test: if you run it or the whole Zend_Queue test battery you don't get any failures. Only if you run tests/Zend/AllTests.php do you see that error and that means (at least to me, although I might be lacking some insight here) that we have some kind weird side effects that have nothing to do with the framework code.

tl;dr: I currently don't know how to give all green check marks.

@glensc
Copy link
Contributor

glensc commented Feb 18, 2021

@falkenhawk @Megatherium I proposed to extract all changes that are ok to a separate PR. I would not be interested in fixing actual bugs right now. I would like to receive the clear Go Ahead signal. Or would you @Megatherium want to do that yourself?

@falkenhawk
Copy link
Member

@glensc please do 🙏

@Megatherium
Copy link
Author

@glensc Please do. Maybe by chopping this stuff up it'll help me to narrow down the source of the remaining problems.

@glensc
Copy link
Contributor

glensc commented Mar 13, 2021

Created 14 PR's as can see from the web:

The last one seems to have issues, probably depends on the change that went to some other pr:

or it could be just a flaky test.

@falkenhawk
Copy link
Member

falkenhawk commented Mar 15, 2021

Closing in favor of multitude of PRs from @glensc . Thank you both!

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