php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52160 Invalid E_STRICT redefined constructor error
Submitted: 2010-06-23 15:21 UTC Modified: 2010-06-26 21:19 UTC
From: manannon at seatiger dot org Assigned: felipe (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.14RC1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: manannon at seatiger dot org
New email:
PHP Version: OS:

 

 [2010-06-23 15:21 UTC] manannon at seatiger dot org
Description:
------------
The following class generates the E_STRICT warning: Strict standards: Redefining already defined constructor for class Log. 

However according to http://php.net/manual/en/language.oop5.decon.php, PHP5 will only assume log() is a constructor if it cannot find a __construct() method:

"For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class."

Since it has already found a __construct() method, it should not assume that log() is also a constructor. 

Test script:
---------------
<?php
class Log
{
	public function __construct() { } 
	public static function log() { }
}

Expected result:
----------------
Nothing

Actual result:
--------------
Strict standards: Redefining already defined constructor for class Log in ....

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-25 01:32 UTC] felipe@php.net
-Status: Open +Status: Analyzed
 [2010-06-25 01:32 UTC] felipe@php.net
"Since it has already found a __construct() method, it should not assume that log() is also a constructor."

Yes, It should not, and actually does not do this. But the E_STRICT is emitted for both cases, though.

I.e.:
class foo {
  function foo() { }
  function __construct() { } // E_STRICT + redefinition
}

class bar {
  function __construct() { }
  function bar() { } // E_STRICT only
}

However, we should change the message for the late.
 [2010-06-25 01:42 UTC] manannon at seatiger dot org
Wouldn't it be better/correct not to emit the E_STRICT at all (for the latter case) rather than just changing the message? The code is 100% correct and according to spec, especially since log() is static. 

This bug makes it impossible to create an E_STRICT clean Log::log() type method (Log->log() is also unavailable if there is a constructor defined).
 [2010-06-26 21:19 UTC] felipe@php.net
-Status: Analyzed +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-06-26 21:19 UTC] felipe@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-26 21:19 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300768
Log: - Fixed bug #52160 (Invalid E_STRICT redefined constructor error)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC