-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH-13177: PHP 8.3.2: final private constructor not allowed when u…
…sed in trait zend_compile has an exception to this rule for constructors using `zend_is_constructor`, which compares the function name to `__construct`. Sadly, `zend_is_constructor` is not a public API, but we can just do the string compare ourselves. Closes GH-13179.
- Loading branch information
Showing
3 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--TEST-- | ||
GH-13177 (PHP 8.3.2: final private constructor not allowed when used in trait) | ||
--FILE-- | ||
<?php | ||
|
||
trait Bar { | ||
final private function __construct() {} | ||
} | ||
|
||
final class Foo1 { | ||
use Bar; | ||
} | ||
|
||
final class Foo2 { | ||
use Bar { | ||
__construct as final; | ||
} | ||
} | ||
|
||
class Foo3 { | ||
use Bar { | ||
__construct as final; | ||
} | ||
} | ||
|
||
trait TraitNonConstructor { | ||
private final function test() {} | ||
} | ||
|
||
class Foo4 { | ||
use TraitNonConstructor { test as __construct; } | ||
} | ||
|
||
for ($i = 1; $i <= 4; $i++) { | ||
$rc = new ReflectionClass("Foo$i"); | ||
echo $rc->getMethod("__construct"), "\n"; | ||
} | ||
|
||
class Foo5 extends Foo3 { | ||
private function __construct() {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Warning: Private methods cannot be final as they are never overridden by other classes in %s on line %d | ||
Method [ <user, ctor> final private method __construct ] { | ||
@@ %sgh13177.php 4 - 4 | ||
} | ||
|
||
Method [ <user, ctor> final private method __construct ] { | ||
@@ %sgh13177.php 4 - 4 | ||
} | ||
|
||
Method [ <user, ctor> final private method __construct ] { | ||
@@ %sgh13177.php 4 - 4 | ||
} | ||
|
||
Method [ <user, ctor> final private method __construct ] { | ||
@@ %sgh13177.php 24 - 24 | ||
} | ||
|
||
|
||
Fatal error: Cannot override final method Foo3::__construct() in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters