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

Do not pass &$parts as reference to resolvePharParentPath #67

Closed
wants to merge 3 commits into from

Conversation

glensc
Copy link
Contributor

@glensc glensc commented Mar 13, 2021

Extracted change made by @Megatherium from #32

@staabm
Copy link
Contributor

staabm commented Mar 13, 2021

offtopic question: I can see lot of PRs from your side, which is awesome.

it seems you are planning to add php8 support to zf1?
(asking for a friend, because we also have some apps still running zf1 ;-))

@glensc
Copy link
Contributor Author

glensc commented Mar 13, 2021

@staabm yes. it's the details all in mr body. click the link there and open the pandora box.

@glensc glensc marked this pull request as ready for review March 13, 2021 15:27
@falkenhawk falkenhawk self-requested a review March 13, 2021 20:06
@glensc
Copy link
Contributor Author

glensc commented Mar 14, 2021

php 5.4 flakyness:


There was 1 error:

1) Zend_Cache_FileBackendTest::testSaveWithNullLifeTime
Zend_Cache_Exception: cache_dir "/home/runner/work/zf1/zf1/tests/Zend/Cache/zend_cache_tmp_dir_031421030011/" must be a directory

/home/runner/work/zf1/zf1/packages/zend-cache/library/Zend/Cache.php:209
/home/runner/work/zf1/zf1/packages/zend-cache/library/Zend/Cache/Backend/File.php:177
/home/runner/work/zf1/zf1/packages/zend-cache/library/Zend/Cache/Backend/File.php:128
/home/runner/work/zf1/zf1/tests/Zend/Cache/FileBackendTest.php:65

Comment on lines +236 to 241
public static function resolvePharParentPath($value, $key, $parts)
{
if ($value !== '...') {
Copy link
Member

@falkenhawk falkenhawk Mar 14, 2021

Choose a reason for hiding this comment

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

I looked at this method and the logic does not make sense to me. The purpose of it was to remove current and previous segment in a path, where current segment was ...? Is triple-dots even ever used in phar paths? Moreover this method would be buggy if ... was at the beginning of a path.

If the original intention was to have .. there instead of ... then it would maybe make more sense... but the logic here to mutate $parts array passed by reference looks awkward and is forbidden in php8 while using array_walk. The change that $parts is no longer a reference is even worse now, because the method would basically do nothing in result in all cases incl. ... value.

It looks like a workaround for a super-rare edge case to me. The case with ... is also not tested. We could try to refactor it in a loop or something, but I think I'd get rid of this method completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@falkenhawk but ths pr did not modify line including if ($value !== '...') {

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it removed reference from $parts which made the method obsolete, but I tried to figure out the original purpose of the method...

Copy link
Member

Choose a reason for hiding this comment

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

Just noticed this #74 - it actually addresses the same issue.
But, I still wonder, why there is a condition for ... inside resolvePharParentPath - it just looks off to me.

Btw, when I change that to .. in #74 to actually allow the $parts array to be modified in tests, ...it crashes in tests for me locally on php 7.3 (win) with a weird error.

composer test tests/Zend/Loader/ClassMapAutoloaderTest.php
> phpunit "tests/Zend/Loader/ClassMapAutoloaderTest.php"
PHPUnit 3.7.38 by Sebastian Bergmann.

Configuration read from D:\projects\ovosdev\zf1s\phpunit.xml.dist

...........Script phpunit handling the test event returned with error code -1073741819

Per https://www.php.net/manual/en/function.array-walk.php :

Only the values of the array may potentially be changed; its structure cannot be altered, i.e., the programmer cannot add, unset or reorder elements. If the callback does not respect this requirement, the behavior of this function is undefined, and unpredictable.

The logic here is definitely not very safe 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved everything but this change to separate PRs, so they won't suffer the delay by code review.

@glensc glensc changed the title Enforce types for PHP 8.0 Do not pass &$parts as reference to resolvePharParentPath Mar 15, 2021
@glensc glensc marked this pull request as draft March 15, 2021 12:03
Alexander Wozniak added 3 commits March 15, 2021 16:43
Signed-off-by: Alexander Wozniak <wozniak@oktopos.com>
Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
In PHP8 the third param of array_walk ($userdata) is automatically
passed by value thus calling a function that expects pass by reference
as the third param is not possible.
Simply changing the array_walk to a foreach loop allows us to fulfill
the pass by reference signature.
@falkenhawk
Copy link
Member

superseded by #111

@falkenhawk falkenhawk closed this Oct 1, 2021
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.

None yet

3 participants