Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

PHP 8.0 & 8.1 #266

Merged
merged 23 commits into from
Nov 25, 2022
Merged

PHP 8.0 & 8.1 #266

merged 23 commits into from
Nov 25, 2022

Conversation

Tybaze
Copy link
Collaborator

@Tybaze Tybaze commented Jun 10, 2022

PHP 8.0 & 8.1 compatibility

[No enhancement - please consider to use Symfony5+ for your new Project]

Target : Maintains maximum backward compatibility down to 5.3.

Backport some fixes from PR #265, but I do not use "internal method return type", because use of "mixed" return type is required.
But "mixed" keyword is not available before PHP 7.4, use anotation instead. 5f2b710

A lot of currently LTS Unix Distro are still running PHP 7.2 / 7.3 currently - and the goal of this repo is to maintain a sf1 running in most setup.

Tests

Great thanks to @alquerci for #262, rebasing with the /test/bin/test dockers tool.
Currently pass all test.

For the moment, to run a successful PHP 8.1 test you should remove E_DEPRECATED or use my last commit for Doctrine1 submodule (Until FriendsOfSymfony1/doctrine1#85 be merged ):

PHP version Dependency Status
php53 highest 🟢
php54 highest 🟢
php55 highest 🟢
php56 highest 🟢
php70 highest 🟢
php71 highest 🟢
php72 highest 🟢
php73 highest 🟢
php74 highest 🟢
php80 highest 🟢
php81 highest 🟢

Future

One day PHP 9 will break compatibility with php < 7.4 due to the lacks of "mixed" keywords implementations.

Please consider rewriting your project to another framework, like Symfony5+ if your app do not support at least PHP 7.4.

@alquerci alquerci mentioned this pull request Jun 10, 2022
Copy link
Contributor

@mentalstring mentalstring left a comment

Choose a reason for hiding this comment

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

Great work done here! 👍 Impressive that we can manage to keep compatibility all way from 5.3 to 8.1. 👌

Caught a few minor things with code style to match symfony1, but otherwise, looks great!

Copy link
Contributor

@mentalstring mentalstring left a comment

Choose a reason for hiding this comment

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

Thanks for tiding up all the details. Looks good to me.

@Tybaze Tybaze requested a review from thePanz August 2, 2022 12:21
@Tybaze
Copy link
Collaborator Author

Tybaze commented Aug 2, 2022

Sorry to be late for the review !

mentalstring added a commit to mentalstring/Propel that referenced this pull request Aug 15, 2022
with code from FriendsOfSymfony1/symfony1#266 to bring Propel sfYaml*.php files in sync
@thirsch
Copy link
Collaborator

thirsch commented Oct 4, 2022

Who is able to merge this pr? As far as I can tell, all requested changes have been fixed.

@thePanz
Copy link
Member

thePanz commented Oct 5, 2022

@Tybaze I would wait for FriendsOfSymfony1/doctrine1#85 to be merged.

In the meantime: can you squash some of the latest commits? (the "apply fix from thePanz", for example, those can go into a single "Apply code-style fixes" together with the other cs-fixes... wdyt? yes, I know, not a good commit message anyway ) :)

@Tybaze
Copy link
Collaborator Author

Tybaze commented Oct 5, 2022

Rebased !
Merged coding style review
Merged small simplications into one commit.

Removed credits in the comments ^^

@@ -1003,10 +1003,10 @@ public function getCurrentCacheKey()
{
$cacheKey = $this->routing->getCurrentInternalUri();

if ($getParameters = $this->request->getGetParameters())
if ($cacheKey && $getParameters = $this->request->getGetParameters())
Copy link
Member

Choose a reason for hiding this comment

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

Is this meant to be here?
we will not consider the parameters if the $cacheKey is an empty string... do we have a test for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

getCurrentInternalUri() can return null (on a sfPatternRouting with a null $currentRouteName)
And in that case on PHP8.1 it will trigger a warning while trying to concatenated the &/?

but on PhP <8.0, it will works and create a $cacheKey containing only the query string.

So this modification will break a empty currentRouteName, as it will not cache the Get parameters anymore

let me fix it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry there is no warning on concatenate on null ...

Copy link
Contributor

@mentalstring mentalstring Oct 5, 2022

Choose a reason for hiding this comment

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

The issue is on the strpos($cacheKey, '?') — I get 3 times the error below for every page request for which the route doesn't exist (e.g. 404 case) that has query parameters in it.

PHP Deprecated:  strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in [...]/vendor/friendsofsymfony1/symfony1/lib/view/sfViewCacheManager.class.php on line 1008

There's no warning if there are no query parameters.

I suppose a more innocuous solution will be to cast the $cacheKey on stripos(), although I'm not sure it makes sense to be generating a cacheKey for a route that doesn't exist and only if it has query parameters. But perhaps in the context of this PR, it's best to avoid any behavior changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As the sfExecutionFilter can handle a null value

$uri = $this->context->getViewCacheManager()->getCurrentCacheKey();
if (null !== $uri && $this->context->getViewCacheManager()->hasActionCache($uri))

So null is a valid value for getCurrentCacheKey() ,
Adding if($cacheKey...) check would break existing feature of enable caching if there are some GET parameters

So I revert this fix in order to keep the existing behavior.

We should need some test to check each possible $cacheKey value

Rebase Done

Copy link
Contributor

@mentalstring mentalstring Oct 5, 2022

Choose a reason for hiding this comment

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

We need to at least cast cacheKey on strpos($cacheKey, '?') or there are deprecation warnings on php8.1 with unnamed routes with parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @mentalstring , I applied your suggestion, by casting the $cacheKey to (string).
It should keep the previous behavior and fix the PHP8.1 warning.

Rebased !

@thePanz is it ok for you ?

Just for fun, I run some benchmark on casting to (string).
On PHP8.1 I got a ~10% overhead to the strpos() call with the cast.

@Tybaze Tybaze force-pushed the compat_php8.1 branch 2 times, most recently from e3d5748 to 716a01f Compare October 6, 2022 07:06
@thirsch
Copy link
Collaborator

thirsch commented Nov 15, 2022

Ping, everything should have been fixed or at least be commented. How about merging and releasing this thing? Thanks for your effort, @Tybaze!

sfException> fileExcerpt file can be null, and PHP 8.1 do not allow null on is_readable()

sfBrowser> Move sf_test conf before getContext, because getContext can throw some sfException, which will raise some printStackTrace, hidden by another Exception "header already sent ..."

lime.php> some trace can have no "file" (internal methods call)
lime.php> handle_exception can handle Error/Throwable, not avaialble under php7.2: remove typing

sfTestFunctionalBase> can throw exception

Fix Select Unit test NewActivePendingExpired.
DomDocument on recent php return a list of values, not concatened ones.

Fix SessionStorage UnitTest.

sfSessionStorage could not be restarted.
Flag $sessionStarted as false when shutdown to avoid error during unit test which can start several sfSessionStorage

Storage need to be shutdown to avoid:
PHP Warning:  session_name(): Session name cannot be changed when a session is active
… "error" value

uncaught exception does not populate error field
…ated, return an integer less than, equal to, or greater than zero
ValueError: fread(): Argument FriendsOfSymfony1#2 ($length) must be greater than 0

TypeError: count(): Argument #1 ($value) must be of type Countable|array Foo Given
Use Symfony Polyfill symfony/polyfill@d330c00

TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given
Do not use Symfony pollyfill, is_array is enought
… null, $accept = false) must be compatible with sfPearRest::downloadHttp($url, $lastmodified = null, $accept = false, $channel = false)
@thePanz thePanz force-pushed the compat_php8.1 branch 4 times, most recently from 81a427e to 6da2c17 Compare November 25, 2022 15:49
8.0.0 	hour is no longer optional.
8.0.0 	minute, second, month, day and year are nullable now.
Numeric strings ending with whitespace ("42 ") will now return true. Previously, false was return instead.

Use same fix has main maintened Yaml lib :
symfony/yaml@4152e36
+ performance improvement
symfony/yaml@2b5f2ae
When $previousIndent was equal to 0, and $matches['indent'] = "    "

PHP(before 8.0)> (0 != "    ") ==> false
PHP8.0+ > (0 != "     ")  ==> true

In order to keep "false" value we avoid "0" as a valid value.

More details here why here:
https://www.php.net/manual/en/migration80.incompatible.php
@thePanz
Copy link
Member

thePanz commented Nov 25, 2022

I applied some additional changes @Tybaze , and fixed the last failure for the ValidatorFile

GitHub actions are now happy for PHP v7.4, v8.0 and v8.1

@thePanz thePanz merged commit 071b8bf into FriendsOfSymfony1:master Nov 25, 2022
@thePanz
Copy link
Member

thePanz commented Nov 25, 2022

Thanks and kudos to @Tybaze for making this possible!

Thanks @thirsch @mentalstring too 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants