php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54512 Strict notice of different method signatures does not appear for constructor
Submitted: 2011-04-12 10:42 UTC Modified: 2012-04-14 03:00 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: gphilip at vipmail dot hu Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.6 OS: Fedora 14
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: gphilip at vipmail dot hu
New email:
PHP Version: OS:

 

 [2011-04-12 10:42 UTC] gphilip at vipmail dot hu
Description:
------------
When a method signature is different in an inherited class and its parent, you get 
a strict notice (assuming they are turned on).

This does not happen with constructors.

Test script:
---------------
<?php

error_reporting( -1 );

class A
{
	public function __construct( $a )
	{	
	}
}

class B extends A
{
	public function __construct( array $a )
	{
	}
}

class C
{
	public function doSomething( $a )
	{
	}
}

class D extends C
{
	public function doSomething( array $a )
	{
	}
}


Expected result:
----------------
Strict Notice Declaration of B::__construct() should be compatible with that of 
A::__construct() in ...

Strict Notice Declaration of D::doSomething() should be compatible with that of 
C::doSomething() in ...

Actual result:
--------------
Strict Notice Declaration of D::doSomething() should be compatible with that of 
C::doSomething() in ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-13 20:45 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2012-04-13 20:45 UTC] nikic@php.net
Constructors are not affected by the Liskov substitution principle, thus they don't need to have a matching signature. See http://stackoverflow.com/questions/5490824/should-constructors-comply-with-the-liskov-substitution-principle for a bit of reasoning.
 [2012-04-14 03:00 UTC] aharvey@php.net
-Status: Closed +Status: Not a bug -Assigned To: nikic +Assigned To:
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 05:01:34 2025 UTC