php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41129 Static interface function cannot contain body
Submitted: 2007-04-18 12:10 UTC Modified: 2007-04-18 13:23 UTC
From: sander at snapworks dot nl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.2RC1 OS: linux 2.6.20-1.2944.fc6
Private report: No CVE-ID: None
 [2007-04-18 12:10 UTC] sander at snapworks dot nl
Description:
------------
PHP doesn't allow static methods in interfaces to have a body.


Reproduce code:
---------------
<?php
interface SomeInterface {
	static public function doSomething() {
	}
}
?>

Expected result:
----------------
A blank page indicating non-failure :) Static methods in interfaces definitely should be allowed to have a body. Maybe it's not a common practise, but it's at times convenient.


Actual result:
--------------
Fatal error: Interface function SomeInterface::doSomething() cannot contain body in /var/www/html/workspace/test.php on line 4


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-18 12:14 UTC] sander at snapworks dot nl
- more descriptive summary
 [2007-04-18 12:15 UTC] tony2001@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


 [2007-04-18 12:26 UTC] sander at snapworks dot nl
I understand this is not a bug, but merely a language construct not being supported. However, where would be the place to report such suggestions, preferably a place where active PHP developers linger?
 [2007-04-18 12:42 UTC] tony2001@php.net
>I understand this is not a bug, but merely a language construct not
>being supported. 

It is not supported because it violates the nature of interfaces.
Use Google to learn why is it unsupported in other languages.

>However, where would be the place to report such
>suggestions, preferably a place where active PHP developers linger?

You're speaking to one.
 [2007-04-18 13:23 UTC] sander at snapworks dot nl
Hi Tony,

I respect your opinion on the fact it would be 
a violation of the nature of interfaces, but I would
like to add that this is a point of view as it depends
on how static members are implemented (wether they are
inheritable and how they are bound). Anyway, I do not
wish to start a discussion on it, because there have
been plenty of them on this subject (notably in the
java world) and it's mostly a matter of choices
made in implementation. I just hoped PHP was going
to support it.

FYI, the reason I needed it was for namespace purposes.
I have a method that is related to an interface, but
is not part of the "contract". And I dislike top-leve
functions. ;) So that's why I wanted to encapsulate
the method inside the interface, not as a part of it,
but more like a way to namespace the method.

Anyway, thanks for your time!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 10:01:31 2024 UTC