Edit report at https://bugs.php.net/bug.php?id=51421&edit=1

 ID:                 51421
 Comment by:         dagguh at gmail dot com
 Reported by:        awood at theiet dot org
 Summary:            Abstract __construct constructor argument list not
                     enforced
 Status:             Closed
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Windows XP SP3
 PHP Version:        5.2SVN-2010-03-29 (snap)
 Assigned To:        felipe
 Block user comment: N
 Private report:     N

 New Comment:

Abstract constructors again.
Learn some basics of OOP.

Why would you EVER want to enforce argument list of a constructor is beyond me.
I bet you are doing something like:
new $iHaveNoClueAboutProgramming($foo, $bar);

Guess what, this code is bad.


Previous Comments:
------------------------------------------------------------------------
[2010-06-28 18:41:25] fel...@php.net

The fix has been reverted for 5.2 and 5.3 branches, due BC issue.

------------------------------------------------------------------------
[2010-06-28 18:38:00] fel...@php.net

Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=300817
Log: - Reverted fix for bug #51421

------------------------------------------------------------------------
[2010-06-27 00:05:15] fel...@php.net

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.



------------------------------------------------------------------------
[2010-06-27 00:05:15] fel...@php.net

Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=300770
Log: - Fixed bug #51421 (Abstract __construct constructor argument list not 
enforced)

------------------------------------------------------------------------
[2010-03-29 01:41:53] awood at theiet dot org

Description:
------------
PHP Version = 5.2.6.6

I cannot seem to enforce a class's __construct argument list by defining an 
abstract constructor in the base class. This can, however, be achieved as 
expected by using an object interface.

This was mistakenly reported as not working for interfaces either in bug #43557 
(closed).

Test script:
---------------
class Type1 {} //for demo purposes
class Type2 {} //for demo purposes

abstract class BaseClass {
   abstract public function __construct(Type1 $foo, Type2 $bar);
}

class ExtendedClass extends BaseClass {
   public function __construct() {
      //expected - fatal error as argument list doesn't match
      //actually happens - nothing, script continues as normal
   }
}

interface SomeInterface {
   public function __construct(Type1 $foo, Type2 $bar);
}

class InterfacedClass implements SomeInterface {
   public function __construct() {
      //generates fatal error as expected
   }
}

Expected result:
----------------
Fatal error when declaring ExtendedClass and InterfacedClass as abstract and 
concrete method signatures are different.

Actual result:
--------------
Only a fatal error when declaring InterfacedClass, no error when declaring 
ExtendedClass.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=51421&edit=1

Reply via email to