|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43557 Abstract constructor arguments can't be enforced
Submitted: 2007-12-10 23:40 UTC Modified: 2008-01-21 01:34 UTC
From: michikono at gmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.2.5 OS: linux
Private report: No CVE-ID: None
 [2007-12-10 23:40 UTC] michikono at gmail dot com
When trying to enforce arguments on constructors, PHP behaves unexpectedly. If you define the constructor as an abstract method in a parent level class, the __construct method argument datatype/count checks go out the window in children. This issue is the same whether its in an interface or abstract class.

Reproduce code:
class ExampleClass {}

interface TestInterface {
	public function __construct(ExampleClass $var);

class Test implements TestInterface {
	public function __construct() {} // NO ERROR (unexpected)

Expected result:
Should produce an error

Actual result:
No error is reported.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-11 00:52 UTC]
PHP 5.3:

Fatal error: Declaration of Test::__construct() must be compatible with that of TestInterface::__construct()
 [2008-01-21 01:34 UTC]
Works as expected in PHP 5.2.6 too.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 17:01:28 2024 UTC