php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #68246 Interface Properties
Submitted: 2014-10-16 21:52 UTC Modified: 2017-09-13 09:42 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: brandon at pixelandtonic dot com Assigned:
Status: Suspended Package: Class/Object related
PHP Version: Irrelevant OS: N/A
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-10-16 21:52 UTC] brandon at pixelandtonic dot com
Description:
------------
Object interfaces should be able to specify public properties that must be defined by classes implementing the interface.

The use case for this is exactly the same as the use case for interfaces specifying public methods that must be on the class: If some PHP code needs to set a property on an object, it should be able to confidently do that, knowing that the property actually exists, simply by knowing that the class implements a particular interface.

There is precedence for this feature in other languages, e.g. http://msdn.microsoft.com/en-US/library/64syzecx(v=vs.80).aspx


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-16 23:45 UTC] php at requinix dot net
If you're going to compare PHP to C# then

PHP has fields, not properties, and I don't know of any language that allows fields on interfaces. Interfaces specify behavior which is what methods are for, not state which is what fields are for.
 [2014-10-17 00:01 UTC] brandon at pixelandtonic dot com
> PHP has fields, not properties

Huh? http://php.net/manual/en/language.oop5.properties.php
 [2014-10-17 00:15 UTC] php at requinix dot net
You cited C# having properties in interfaces as an example of why PHP should have properties in interfaces, but you can't compare the two like that because PHP's "properties" are C#'s "fields" (actual member variables) and C#'s "properties" don't have an equivalent in PHP (what looks like member variables but are in fact methods hidden by syntactic sugar).

If you want a correct comparison then you need to say that C#'s interfaces support fields therefore PHP's interfaces should support properties. Except that's not true. So that argument doesn't hold water.
 [2017-09-13 09:42 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2017-09-13 09:42 UTC] cmb@php.net
Thank you for your interest in PHP and for submitting a feature
request. Please be aware that due to the magnitude of change this
request requires, it would be necessary to discuss it on PHP
Internals list (internals@lists.php.net) as an RFC. Please read
the guide about creating RFCs here:
<https://wiki.php.net/rfc/howto>. If you haven't had experience
with writing RFCs before, it is advised to seek guidance on the
Internals list (<http://php.net/mailing-lists.php>) and/or solicit
help from one of the experienced developers. 

Please do not consider this comment as a negative view on the
merits of your proposal – every proposal which requires changes of
certain magnitude, even the very successful and widely supported
ones, must be done through the RFC process. This helps make the
process predictable, transparent and accessible to all developers.

See also <https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented>
for an overview of existing RFCs proposing property accessors.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Oct 25 17:01:24 2020 UTC