Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Fix for PHP 7.4#195

Merged
michalbundyra merged 3 commits into
zendframework:masterfrom
remicollet:issue-php74
Oct 11, 2019
Merged

Fix for PHP 7.4#195
michalbundyra merged 3 commits into
zendframework:masterfrom
remicollet:issue-php74

Conversation

@remicollet

Copy link
Copy Markdown
Contributor

The second commit revels an issue with current code.

Zend\View\Variable implements ArrayObject but array_key_exists doesn't work in this case, as eplained in https://wiki.php.net/rfc/deprecations_php_7_4

This PR is not complete, as with 7.4.0RC3 I still encounter an issue
There were 2 errors:


1) ZendTest\View\Helper\PartialLoopTest::testNestedCallsShouldNotOverrideObjectKey
Trying to get property 'helper' of non-object

/dev/shm/BUILD/zend-view-4f5cb653ed4c64bb8d9bf05b294300feb00c67f2/test/Helper/_files/modules/application/views/scripts/partialLoopChildObject.phtml:10
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Renderer/PhpRenderer.php:506
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/Partial.php:61
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/PartialLoop.php:83
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/PartialLoop.php:61
/dev/shm/BUILD/zend-view-4f5cb653ed4c64bb8d9bf05b294300feb00c67f2/test/Helper/_files/modules/application/views/scripts/partialLoopParentObject.phtml:15
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Renderer/PhpRenderer.php:506
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/Partial.php:61
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/PartialLoop.php:83
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/PartialLoop.php:61
/dev/shm/BUILD/zend-view-4f5cb653ed4c64bb8d9bf05b294300feb00c67f2/test/Helper/PartialLoopTest.php:329

2) ZendTest\View\Helper\PartialLoopTest::testNestedCallsShouldNotOverrideObjectKeyInLoopMethod
Trying to get property 'helper' of non-object

/dev/shm/BUILD/zend-view-4f5cb653ed4c64bb8d9bf05b294300feb00c67f2/test/Helper/_files/modules/application/views/scripts/partialLoopChildObject.phtml:10
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Renderer/PhpRenderer.php:506
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/Partial.php:61
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/PartialLoop.php:83
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/PartialLoop.php:61
/dev/shm/BUILD/zend-view-4f5cb653ed4c64bb8d9bf05b294300feb00c67f2/test/Helper/_files/modules/application/views/scripts/partialLoopParentObject.phtml:15
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Renderer/PhpRenderer.php:506
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/Partial.php:61
/dev/shm/BUILDROOT/php-zendframework-zend-view-2.11.2-1.fc29.remi.x86_64/usr/share/php/Zend/View/Helper/PartialLoop.php:83
/dev/shm/BUILD/zend-view-4f5cb653ed4c64bb8d9bf05b294300feb00c67f2/test/Helper/PartialLoopTest.php:640

@michalbundyra

Copy link
Copy Markdown
Member

See #192

@michalbundyra michalbundyra added this to the 2.11.3 milestone Oct 10, 2019
@remicollet

Copy link
Copy Markdown
Contributor Author

@webimpress sorry I miss this PR,

BTW second commit still make sense ?

@michalbundyra

Copy link
Copy Markdown
Member

@remicollet

sorry I miss this PR,

no problem 👍

second commit still make sense ?

yeah, but...

isset !== array_key_exists as you know, so in this case I can find failing test case, for example:

$model->setVariables(['test' => null], true);
$model->getVariable('test', 'default');

before we got null, now we are gonna get default.

Because of that, I think we need change the condition:

if (is_array($this->variables)) {
    if (array_key_exists($name, $this->variables)) {
        return $this->variables[$name];
    }
} elseif ($this->variables->offsetExists($this->variables)) {
    return $this->variables[$name];
}

return $default;

or something like that, haven't tested yet. Do you know what I mean?

@remicollet

remicollet commented Oct 10, 2019

Copy link
Copy Markdown
Contributor Author

Yes, As I explain in initial description, there is some issue.

In current code array_key_exists is used which have never work for ArrayAccess, so don't know how it works (test suite) with PHP <= 7.3

(so this trivial PR preserve current behavior, which is perhaps broken)

@michalbundyra

Copy link
Copy Markdown
Member

@remicollet Ok, thanks, I'll have a look on it later on and will try to release bugfix version with PHP 7.4 compatibility later today. Thanks for your effort!

From PHP 7.4 docs:

    Calling get_object_vars() on an ArrayObject instance will now always return
    the properties of the ArrayObject itself (or a subclass). Previously it
    returned the values of the wrapped array/object unless the STD_PROP_LIST
    flag was specified. Other affected operations are:

     * ReflectionObject::getProperties()
     * reset(), current(), etc. Use Iterator methods instead.
     * Potentially others working on object properties as a list.
@michalbundyra

michalbundyra commented Oct 10, 2019

Copy link
Copy Markdown
Member

@remicollet I've fixed other failing tests - see commit c711fbd.
So current function on object is not working either - https://3v4l.org/kZidu

I've changed your fix to keep the previous behaviour and added tests to cover the fix.
Let me know what do you think please.

(BTW. yeah, I do not like it too much, but I don't want introduce BC break with the fix...)

Comment thread src/Model/ViewModel.php
if (array_key_exists($name, $this->variables)) {
return $this->variables[$name];
}
} elseif ($this->variables->offsetExists($name)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Don't you want to check if this is an ArrayAccess object first ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As I can see from the code (construct, setter...) it must be an array or Zend\View\Variables (extends ArrayObject), so I think no additional check is needed here.

@remicollet

Copy link
Copy Markdown
Contributor Author

Tested 2.11.2 + pr #192 + pr #195
Everything seems ok

echo $vars['message'];
} else {
$objKey = current($this->vars())->helper->getObjectKey();
$objKey = current($vars)->helper->getObjectKey();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice,

This BC break on ArrayAccess object in 7.4 is terrible
Already bitten on another project, not easy to catch

@remicollet

Copy link
Copy Markdown
Contributor Author

FYI, according to Fedora CI, excepted zend-server, ZF seems in good shape for 7.4

@michalbundyra

Copy link
Copy Markdown
Member

Thanks, @remicollet!

@michalbundyra michalbundyra merged commit 81ed6ca into zendframework:master Oct 11, 2019
michalbundyra added a commit that referenced this pull request Oct 11, 2019
michalbundyra added a commit that referenced this pull request Oct 11, 2019
michalbundyra added a commit that referenced this pull request Oct 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants