php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50015 Overwriting method of parent class with additional parameters. Strict standards
Submitted: 2009-10-27 10:53 UTC Modified: 2009-10-27 12:51 UTC
From: shaselboeck at m-s dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.11 OS: Windows 2000 Server
Private report: No CVE-ID: None
 [2009-10-27 10:53 UTC] shaselboeck at m-s dot de
Description:
------------
If I turn on E_STRICT, I get a strict notice depending on class
position. The notice is as following:

Strict standards: Declaration of ... should be compatible with that of
...

Maybe this notice is correct, but if I switch the classes in my code
without changing their content, this notice is gone. Exactly here is the bug.

In example A and B the method someFunc() of child class is not compatible with that of parent class. But only in example A occurs an error (Strict standards... see above)

Reproduce code:
---------------
<?php
error_reporting(E_ALL | E_STRICT);

/**
 * Example A: error occurs
 */
class Child_A extends Parent_A
{
    public function someFunc($param) {}
}
class Parent_A
{
    public function someFunc() {}
}

$child = new Child_A();


/**
 * Example B: no error occurs
 */
class Parent_B
{
    public function someFunc() {}
}
class Child_B extends Parent_B
{
    public function someFunc($param) {}
}

$child = new Child_B();

Expected result:
----------------
Either both examples (A and B ) should trigger an error or no one of them.

Parent classes should be parsed before child classes which extends parent classes.

Actual result:
--------------
Code example A triggers an error:

Strict Standards: Declaration of Child_A::someFunc() should be compatible with that of Parent_A::someFunc() in E:\...\class_extending_test.php on line 7

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-27 11:50 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

In the second case the message is produced while compiling the script, before the error_reporting() function call happens. Set the error_reporting level in your php.ini and you will see the notice in both cases.
 [2009-10-27 12:51 UTC] shaselboeck at m-s dot de
Thanks!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 24 00:00:03 2025 UTC