php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36066 Allowing member variables in interfaces
Submitted: 2006-01-18 12:20 UTC Modified: 2018-05-05 17:59 UTC
Votes:4
Avg. Score:4.2 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: pablobm at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.1.2 OS: Any
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: pablobm at gmail dot com
New email:
PHP Version: OS:

 

 [2006-01-18 12:20 UTC] pablobm at gmail dot com
Description:
------------
Maybe it's just me, but I think member variables should be allowed in object interfaces.

My opinion is that this makes sense in PHP because it has proper getters/setters.

Java allows mamber variables in interfaces for example, but, in its case, that doesn't make much sense, since (last time I checked, in 1.4) there are no proper getter/setter methods in Java as those found in PHP5.

If I want an interface to define behaviour for a data structure that holds information, I will have to include getMember() and setMember() methods, not being able to use PHP5 getters/setters.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-05 04:30 UTC] alpha_centurion at hotmail dot com
I'd agree with this. Both from the perspective of people coming into PHP from other languages and an OO purist, the capacity to define public properties in interfaces is integral to their function.

Although there is an argument which could support using interfaces purely for method signatures, it is more academic than practical and typically ends with some idea of separating property-focused interfaces from method-focused interfaces (facets of functionality).

The usage strategy is something that should be decided in the implementation of software built on the language; the provision of the base functionality seems a logical (and necessary) progression of the language.
 [2018-05-05 17:59 UTC] requinix@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2018-05-05 17:59 UTC] requinix@php.net
Old request is old.

The original request doesn't make sense to me. PHP only has methods (which can be getters and setters, in the traditional sense of one-liner methods that get/set a value) and the magic __get/set, all of which can be required through an interface. PHP does not have what I would call "proper getter/setter methods" like C#'s properties.

Anyways, the request to support variables in interfaces would require the RFC process. https://wiki.php.net/rfc/howto
However PHP 5.4 added traits for easier code reuse, and they support variables.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 04:01:29 2024 UTC