4

I've already read a related topic here Function with same name but different signature in derived class.

I think the problem is the same but in my case it happens in PHP 5.4 (in PHP 5.3 works fine). The specific configuration is wamp 2.2, PHP 5.4.3. I can't see any errors in the logs and Chrome browser shows the following: "Error 101 (net::ERR_CONNECTION_RESET): The connection was reset."

If I change the name of the function "init" in my example below, everything works fine. So I know what to do, but I would like to make sure that it is a bad practice in general for the same reasons explained in the related question. It would be helpful if PHP showed an error, I don't know what is going on in the internals.

Any thoughts?

Thank you

class MyClass1 {

    private function init(){

    }
}

class MyClass2 extends MyClass1 {

    private function init($params) {

    }
}

$myinstance = new MyClass2();
Community
  • 1
  • 1
aitorlape
  • 51
  • 5

2 Answers2

2

I've just been looking up the PHP changelog and found something that might be relevant.

An item in the release notes for 5.4.4 reads as follows:

Fixed bug #61761 ('Overriding' a private static method with a different signature causes crash)

That sounds very much like what you're seeing, especially since you specified that you're using PHP 5.4.3.

As per my comment earlier, I would therefore suggest upgrading to a newer release of 5.4 (preferably the latest -- currently 5.4.8).

Hope that helps.

SDC
  • 14,192
  • 2
  • 35
  • 48
  • Oh, thanks so much. This seems to be the problem, but if it is considered a bug, I guess that from the programming language perspective it is not a bad practice as pointed out in the related topic. – aitorlape Nov 16 '12 at 12:00
  • 1
    Re bad practice... Well, I wouldn't consider it *that* bad, but I've not really thought about it before. But I can see why it might not be a good idea due to the confusion it could cause someone reading the code. The argument falls apart somewhat in cases where you don't have visibility of the private methods in the base class so you wouldn't know that you're using the same name, but that doesn't apply here. – SDC Nov 16 '12 at 12:22
0

From the error you're getting in Chrome, I would guess PHP is crashing (hence no meaningful error). I would start by disabling some extensions, maybe checking your event viewer for any crash information.

shevron
  • 3,463
  • 2
  • 23
  • 35
  • yep, I'd definitely start by updating to the latest release of 5.4 (currently 5.4.8), in case you've hit a bug that was in a specific release. Try running your script from the command line, as that might give you more helpful crash info. If it still crashes in the latest version and you've got a simple example program that can demonstrate it, try posting a bug report to PHP.net. If it is a bug, I'd be surprised if it's as simple as it looks in the question, because overloading a method with a differnt number of arguments in an extension class is hardly an unusual thing to do. – SDC Nov 16 '12 at 11:48
  • I've disabled a few ones but the "error" is still happening. The code is so simple that I guess it is related to the topic I link in my question, but I am not sure. The Event Viewer shows Faulting application name: httpd.exe, version: 2.2.22.0, time stamp: 0x4faf9b60 Faulting module name: php5ts.dll, version: 5.4.3.0, time stamp: 0x4fa864bc Exception code: 0xc0000005 Fault offset: 0x00319e6a Faulting process id: 0x1020 Faulting application start time: 0x01cdc3ef8a49b843 – aitorlape Nov 16 '12 at 11:50
  • So do you think it is a bad practice to use the same name function in a derived class with a different signature, this applies to every programming language?, could be the reason?. I am going to update but I would also going to update the code if this bad practice could scale to something worst. I showed a simple example, but my code involves a lot of classes, derived classes, namespaces and so on – aitorlape Nov 16 '12 at 11:55