php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: michikono at gmail dot com
New email:
PHP Version: OS:

 

 [2007-12-10 23:40 UTC] michikono at gmail dot com
Description:
------------
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-11 00:52 UTC] felipe@php.net
PHP 5.3:

Fatal error: Declaration of Test::__construct() must be compatible with that of TestInterface::__construct()
 [2008-01-21 01:34 UTC] felipe@php.net
Works as expected in PHP 5.2.6 too.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC