Skip to content

Commit

Permalink
minor #359 [PHP80] Prevent redefinition of PHP 8.0 classes (Firtzberg)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.23-dev branch.

Discussion
----------

[PHP80] Prevent redefinition of PHP 8.0 classes

Not redeclaring polyfilled classes when PHP version is 8.0 or above.
The same approach is used for the Stringable interface in [this commit](symfony/polyfill@8a3e849).

One of my scripts runs [`opcache_compile_file`](https://www.php.net/manual/en/function.opcache-compile-file.php) on vendor files, including symfony. I'm in the process of upgrading to PHP 8. Running `opcache_compile_file` on either of the modified files causes a fatal error `Fatal error: Cannot declare class ValueError/UnhandledMatchError, because the name is already in use`.
That's not the case on PHP versions below 8.

Commits
-------

f1854da Not redeclaring polyfilled classes when PHP version is target or above
nicolas-grekas committed Sep 13, 2021
2 parents 1100343 + c77f0f8 commit 57b712b
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Resources/stubs/UnhandledMatchError.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

class UnhandledMatchError extends Error
{
if (\PHP_VERSION_ID < 80000) {
class UnhandledMatchError extends Error
{
}
}
6 changes: 4 additions & 2 deletions Resources/stubs/ValueError.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

class ValueError extends Error
{
if (\PHP_VERSION_ID < 80000) {
class ValueError extends Error
{
}
}

0 comments on commit 57b712b

Please sign in to comment.