Req #68246 [Com]: Interface Properties

From: Date: Fri, 17 Oct 2014 00:15:39 +0000
Subject: Req #68246 [Com]: Interface Properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188150@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68246&edit=1 ID: 68246 Comment by: php at requinix dot net Reported by: brandon at pixelandtonic dot com Summary: Interface Properties Status: Open Type: Feature/Change Request Package: Class/Object related Operating System: N/A PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2014-10-17 00:01:12] brandon at pixelandtonic dot com > PHP has fields, not properties Huh? http://php.net/manual/en/language.oop5.properties.php ------------------------------------------------------------------------ [2014-10-16 23:45:02] 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-16 21:52:03] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68246&edit=1

« previous php.bugs (#188150) next »