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

PHP 8.3.2: final private constructor not allowed when used in trait #13177

Closed
ondrejmirtes opened this issue Jan 17, 2024 · 0 comments
Closed

Comments

@ondrejmirtes
Copy link
Contributor

Description

The following code:

<?php

final class Foo {
    
    use Bar;
}

trait Bar {
    
    final private function __construct() {}
    
}

Resulted in this output:

Warning: Private methods cannot be final as they are never overridden by other classes in /in/4sc3H on line 3

But I expected this output instead:

No error

Constructors CAN be private AND final, as opposed to normal methods.

This is a wrong side effect of this fix: #12857

Please make sure that the version with trait usage is also allowed:

<?php

final class Foo {
    
    use Bar {
        __construct as final;
    }
}

trait Bar {
    
    private function __construct() {}
    
}

PHP Version

PHP 8.3.2

Operating System

N/A

@nielsdos nielsdos self-assigned this Jan 17, 2024
nielsdos added a commit to nielsdos/php-src that referenced this issue Jan 17, 2024
…n used 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.
nielsdos added a commit that referenced this issue Jan 19, 2024
* PHP-8.3:
  Fix GH-13177: PHP 8.3.2: final private constructor not allowed when used in trait
  Fix GH-12107: When running a stored procedure (that returns a result set) twice, PHP crashes
mpyw added a commit to mpyw/sharable-value-objects that referenced this issue Jan 22, 2024
mpyw added a commit to mpyw/sharable-value-objects that referenced this issue Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants