php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30793 Abstract functions and default parameter
Submitted: 2004-11-15 13:48 UTC Modified: 2012-02-25 00:36 UTC
Votes:10
Avg. Score:3.9 ± 0.9
Reproduced:6 of 10 (60.0%)
Same Version:5 (83.3%)
Same OS:2 (33.3%)
From: jonas at datatal dot se Assigned: stas (profile)
Status: Closed Package: Class/Object related
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jonas at datatal dot se
New email:
PHP Version: OS:

 

 [2004-11-15 13:48 UTC] jonas at datatal dot se
Description:
------------
Don't know if this is a bug or a feature request. Any case, it's a Zend 2 problem..



Reproduce code:
---------------
<?php

abstract class DbClass
{
	protected $m_con;
	
	public function  __construct(ADOConnection $con)
	{
		$this->m_con = $con;
	}

	/** Factory method to create an object from the database */
	abstract public static function Get(ADOConnection $con, $id, $localeId);
}

class User extends dbClass
{
	public static function Get(ADOConnection $con, $id, $localeId = 1053)
	{
		
	}
	
}

?>

Expected result:
----------------
Should be possible to assign default values to parameters in overloaded abstract functions.

Actual result:
--------------
Fatal error: Declaration of User::Get() must be compatible with that of DbClass::Get() in d:\projects\inetpub\WebUser\test.php on line 23

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-15 13:59 UTC] jonas at datatal dot se
Another related problem.

have this function in the same abstract class:

/** Fill the object with the information fetched from the db */
abstract public static function Fill(ADORecordset $rs, DbClass $db);

Since all db classes extends the DbClass this should be valid:

(in the user class)
public static function Fill(ADORecordset $rs, User $usr)
{
  [...]
}

but it isnt. I get the following error:

Fatal error: Declaration of User::Fill() must be compatible with that of DbClass::Fill() in d:\projects\inetpub\WebUser\Classes\User.php on line 83
 [2004-11-27 11:40 UTC] tony2001@php.net
Well, personally I do not think such features could be accepted.
You get these errors because method signatures are different (number of required arguments and class hint differ), so this is well expected behaviour.

I'm leaving this report as feature request for Andi.
 [2004-11-29 15:54 UTC] jonas at datatal dot se
I can agree on the second problem. But the first one should be valid (default parameter is still a parameter)
 [2004-11-29 15:57 UTC] tony2001@php.net
>default parameter is still a parameter
right.
but providing default value for a parameter you're changing the number of required arguments.
 [2010-12-20 14:05 UTC] jani@php.net
-Package: Feature/Change Request +Package: Class/Object related -Operating System: +Operating System: * -PHP Version: 5.0.2 +PHP Version: *
 [2012-02-25 00:35 UTC] stas@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Seems to be working fine in 5.3.
 [2012-02-25 00:35 UTC] stas@php.net
-Status: Assigned +Status: Feedback
 [2012-02-25 00:36 UTC] stas@php.net
-Status: Feedback +Status: Closed -Assigned To: andi +Assigned To: stas
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 16:01:29 2024 UTC