php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75202 Interfaces shouldn't be able to define a constructor
Submitted: 2017-09-13 09:34 UTC Modified: 2017-09-13 15:08 UTC
From: kelunik@php.net Assigned: cmb (profile)
Status: Closed Package: Class/Object related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2017-09-13 09:34 UTC] kelunik@php.net
Description:
------------
Interfaces shouldn't be able to enforce a signature for `__construct`. Parent classes can't enforce that either, for classes there's no compatibility check, but interfaces have them.

See https://3v4l.org/mSPL5 vs. https://3v4l.org/RYdFG

This is related to #50302 which I believe is a bug, even if it has been closed as not being one.

In case it's decided that this is not a bug, this bug can serve as documentation of it not being a bug.

Expected result:
----------------
Probably a compile time error, that the interface defines __construct.

Actual result:
--------------
The interface is defined with __construct and the signature enforced in classes implementing it.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-13 13:34 UTC] kelunik@php.net
-Package: Scripting Engine problem +Package: Class/Object related
 [2017-09-13 13:45 UTC] cmb@php.net
I think this issue should be discussed in internals, Niklas.
 [2017-09-13 14:12 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2017-09-13 14:12 UTC] nikic@php.net
While constructors are generally exempt from LSP, enforcing consistent constructor signatures can be useful in some contexts, e.g. for use by factories. This is an intentional feature and will not be dropped.
 [2017-09-13 15:06 UTC] cmb@php.net
-Status: Not a bug +Status: Analyzed -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2017-09-13 15:06 UTC] cmb@php.net
> In case it's decided that this is not a bug, this bug can serve
> as documentation of it not being a bug.

Switching to doc issue.
 [2017-09-13 15:07 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=343082
Log: Fixed bug #75202 (Interfaces shouldn't be able to define a constructor)

We document that interfaces allow constructors to be declared.
 [2017-09-13 15:08 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=7c0b830e9873c60aaf18ea6dee38a6022a2c2576
Log: Fixed bug #75202 (Interfaces shouldn't be able to define a constructor)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 05:01:28 2024 UTC