php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44318 introducing default params values in overridden methods throws E_STRICT
Submitted: 2008-03-03 16:23 UTC Modified: 2008-03-05 09:32 UTC
From: Fahr at lycantrope dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.5 OS: FreeBSD 7.0
Private report: No CVE-ID: None
 [2008-03-03 16:23 UTC] Fahr at lycantrope dot com
Description:
------------
Introducing a parameter with a default value in a function of a derived class, where the function in the parent does not have a default value, throws an E_STRICT.

Introducing a default does NOT change the function's signature and should not cause any problems. It is possible in C++ and most other OO languages without any issues. In PHP it causes an E_STRICT to be thrown.

This is especially an issue when working with third party libraries (i.e. Smarty) that need to be overridden to have defaults (i.e. display()/fetch()). This works fine, but does throw an E_STRICT.

Reproduce code:
---------------
class Parent
{
  public function foo($bar)
  {
  }
}

class Child extends Parent
{
  public function foo($bar = "test")
  {
  }
}

Expected result:
----------------
No E_STRICT thrown

Actual result:
--------------
E_STRICT thrown

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-05 09:32 UTC] jani@php.net
If you don't want to code in strict way, then remove E_STRICT from your error_reporting setting in php.ini. This is not a bug. 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 08 10:01:33 2025 UTC