Req #49526 [Com]: C# style property get/set syntax

2013-03-02 Thread re...@php.net
Edit report at https://bugs.php.net/bug.php?id=49526&edit=1

 ID: 49526
 Comment by: re...@php.net
 Reported by:president at basnetworks dot net
 Summary:C# style property get/set syntax
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

@see https://wiki.php.net/rfc/propertygetsetsyntax-v1.2

this RFC failed to win the vote sadly.


Previous Comments:

[2013-01-09 01:36:22] anka17pinky at yahoo dot com

I wish this request was implemented in PHP 5.5 :(

There are so many questions on SO asking for ways to implement readonly 
properties in PHP...


[2012-01-28 01:45:53] phpdev at zerocue dot com

An "as implemented" document has been created here:
https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented

Only thing remaining to be implemented is static accessors.


[2010-10-28 00:48:47] rayro at gmx dot de

I also recommend this but i have a little idea too:

1. Most of the time i use get() syntax and I have to write new 
functions for that (or using __call or __set), because i protect the properties 
with private or protected to protect for writing them.
2. Most of all the code is ugly or has limitations using readonly/writeonly 
properties with __get(&$v) or __set($v,&$c) by reference.
3. It is not perfectly clean to write less code with __get or getter/setter if 
only want to protecting them... And less code matters!

I would like to see a new, or 2 new keywords, e.g. "readonly" and "writonly", 
because the code will look smoother and i dont have to make the use of magic 
methods... Or some own designed errors for that...

Now an simple example:
==



( what about is_readable() or is_writable() for that? )
I dont think that these functions will be used, so only Reflection should be 
extended...

and now, instead of the current syntax:
==

$v;
  }
  function __set($v, $c)
  {
if ($v == 'foo') {
  trigger_error('$foo is not writable from this context',E_USER_ERROR);
}
$this->$v = $c;
return true;
  }
}
?>

get/set syntax will be nice but also nasty if only read/writablity is desired...

this can be confusing as this:
==
foo;
}
function __set() {
  trigger_error('$foo is not writable from this context',E_USER_ERROR);
}
  } = 1;
  static protected $bar {
function __get() {
  trigger_error('$bar is not readable from this context',E_USER_ERROR);
}
function __set() {
  $this->bar = 1;
  return true;
}
  } = 2;
}
?>

think about it... many developers will waive the old way or functions like 
getVarname and setVarname... and for all other, getter/setter will be nice as 
described in the rfc...


[2009-09-13 19:56:24] president at basnetworks dot net

For reference, the RFC for this feature request now exists at this URL:

http://wiki.php.net/rfc/propertygetsetsyntax


[2009-09-13 04:24:08] president at basnetworks dot net

Hi Kalle,

Thanks for the information.  I will follow your instructions and start working 
on the RFC over the next week(s).  Also, thanks for the link about the 
Developer Summit, but it does not show the outcome of the discussion, am I able 
to find that anywhere?




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=49526


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=49526&edit=1


Req #49526 [Com]: C# style property get/set syntax

2013-01-08 Thread anka17pinky at yahoo dot com
Edit report at https://bugs.php.net/bug.php?id=49526&edit=1

 ID: 49526
 Comment by: anka17pinky at yahoo dot com
 Reported by:president at basnetworks dot net
 Summary:C# style property get/set syntax
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

I wish this request was implemented in PHP 5.5 :(

There are so many questions on SO asking for ways to implement readonly 
properties in PHP...


Previous Comments:

[2012-01-28 01:45:53] phpdev at zerocue dot com

An "as implemented" document has been created here:
https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented

Only thing remaining to be implemented is static accessors.


[2010-10-28 00:48:47] rayro at gmx dot de

I also recommend this but i have a little idea too:

1. Most of the time i use get() syntax and I have to write new 
functions for that (or using __call or __set), because i protect the properties 
with private or protected to protect for writing them.
2. Most of all the code is ugly or has limitations using readonly/writeonly 
properties with __get(&$v) or __set($v,&$c) by reference.
3. It is not perfectly clean to write less code with __get or getter/setter if 
only want to protecting them... And less code matters!

I would like to see a new, or 2 new keywords, e.g. "readonly" and "writonly", 
because the code will look smoother and i dont have to make the use of magic 
methods... Or some own designed errors for that...

Now an simple example:
==



( what about is_readable() or is_writable() for that? )
I dont think that these functions will be used, so only Reflection should be 
extended...

and now, instead of the current syntax:
==

$v;
  }
  function __set($v, $c)
  {
if ($v == 'foo') {
  trigger_error('$foo is not writable from this context',E_USER_ERROR);
}
$this->$v = $c;
return true;
  }
}
?>

get/set syntax will be nice but also nasty if only read/writablity is desired...

this can be confusing as this:
==
foo;
}
function __set() {
  trigger_error('$foo is not writable from this context',E_USER_ERROR);
}
  } = 1;
  static protected $bar {
function __get() {
  trigger_error('$bar is not readable from this context',E_USER_ERROR);
}
function __set() {
  $this->bar = 1;
  return true;
}
  } = 2;
}
?>

think about it... many developers will waive the old way or functions like 
getVarname and setVarname... and for all other, getter/setter will be nice as 
described in the rfc...


[2009-09-13 19:56:24] president at basnetworks dot net

For reference, the RFC for this feature request now exists at this URL:

http://wiki.php.net/rfc/propertygetsetsyntax


[2009-09-13 04:24:08] president at basnetworks dot net

Hi Kalle,

Thanks for the information.  I will follow your instructions and start working 
on the RFC over the next week(s).  Also, thanks for the link about the 
Developer Summit, but it does not show the outcome of the discussion, am I able 
to find that anywhere?


[2009-09-12 12:22:19] ka...@php.net

Hey

The best way to request this feature is to write an RFC in our wiki at:
http://wiki.php.net/rfc/

Request an account at:
http://wiki.php.net/start?do=register

And then send an email to the webmaster list (php-webmas...@lists.php.net) 
requesting write access to the rfc namespace and repost this feature request as 
an RFC. When you are done, start a new thread on internals 
(intern...@lists.php.net) explaining your RFC.

As for reference, this idea was discussed at the last PDM in May, see:
http://wiki.php.net/summits/pdmnotesmay09#php_6 point #16




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=49526


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=49526&edit=1


Req #49526 [Com]: C# style property get/set syntax

2012-01-27 Thread phpdev at zerocue dot com
Edit report at https://bugs.php.net/bug.php?id=49526&edit=1

 ID: 49526
 Comment by: phpdev at zerocue dot com
 Reported by:president at basnetworks dot net
 Summary:C# style property get/set syntax
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

An "as implemented" document has been created here:
https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented

Only thing remaining to be implemented is static accessors.


Previous Comments:

[2010-10-28 00:48:47] rayro at gmx dot de

I also recommend this but i have a little idea too:

1. Most of the time i use get() syntax and I have to write new 
functions for that (or using __call or __set), because i protect the properties 
with private or protected to protect for writing them.
2. Most of all the code is ugly or has limitations using readonly/writeonly 
properties with __get(&$v) or __set($v,&$c) by reference.
3. It is not perfectly clean to write less code with __get or getter/setter if 
only want to protecting them... And less code matters!

I would like to see a new, or 2 new keywords, e.g. "readonly" and "writonly", 
because the code will look smoother and i dont have to make the use of magic 
methods... Or some own designed errors for that...

Now an simple example:
==



( what about is_readable() or is_writable() for that? )
I dont think that these functions will be used, so only Reflection should be 
extended...

and now, instead of the current syntax:
==

$v;
  }
  function __set($v, $c)
  {
if ($v == 'foo') {
  trigger_error('$foo is not writable from this context',E_USER_ERROR);
}
$this->$v = $c;
return true;
  }
}
?>

get/set syntax will be nice but also nasty if only read/writablity is desired...

this can be confusing as this:
==
foo;
}
function __set() {
  trigger_error('$foo is not writable from this context',E_USER_ERROR);
}
  } = 1;
  static protected $bar {
function __get() {
  trigger_error('$bar is not readable from this context',E_USER_ERROR);
}
function __set() {
  $this->bar = 1;
  return true;
}
  } = 2;
}
?>

think about it... many developers will waive the old way or functions like 
getVarname and setVarname... and for all other, getter/setter will be nice as 
described in the rfc...


[2009-09-13 19:56:24] president at basnetworks dot net

For reference, the RFC for this feature request now exists at this URL:

http://wiki.php.net/rfc/propertygetsetsyntax


[2009-09-13 04:24:08] president at basnetworks dot net

Hi Kalle,

Thanks for the information.  I will follow your instructions and start working 
on the RFC over the next week(s).  Also, thanks for the link about the 
Developer Summit, but it does not show the outcome of the discussion, am I able 
to find that anywhere?


[2009-09-12 12:22:19] ka...@php.net

Hey

The best way to request this feature is to write an RFC in our wiki at:
http://wiki.php.net/rfc/

Request an account at:
http://wiki.php.net/start?do=register

And then send an email to the webmaster list (php-webmas...@lists.php.net) 
requesting write access to the rfc namespace and repost this feature request as 
an RFC. When you are done, start a new thread on internals 
(intern...@lists.php.net) explaining your RFC.

As for reference, this idea was discussed at the last PDM in May, see:
http://wiki.php.net/summits/pdmnotesmay09#php_6 point #16


[2009-09-11 01:02:26] president at basnetworks dot net

Description:

I would like to request a C# style get/set syntax (called a property in C#) for 
PHP.  Basically, it looks and acts like a class member/variable from outside 
the class, but it is actually a set of two methods.  It can be used to provide 
only read or write access to a class member, do pre or post processing on a 
member, or be completely dynamic like a set of class methods.

A property contains two methods between braces, named get and set.  get must 
always have a return statement, while set has a magic variable "value" or 
"$value" which is the variable that was passed to the property.  Either method 
can be omitted to make the property read-only or write-only.

The same effect can be achieved by creating a GetVar() and SetVar() method to 
create a sudo-property "var", although it is by far much clumsier and less 
intuitive.

I also realize the same effect received outside

Req #49526 [Com]: C# style property get/set syntax

2010-10-27 Thread rayro at gmx dot de
Edit report at http://bugs.php.net/bug.php?id=49526&edit=1

 ID: 49526
 Comment by: rayro at gmx dot de
 Reported by:president at basnetworks dot net
 Summary:C# style property get/set syntax
 Status: Open
 Type:   Feature/Change Request
 Package:Feature/Change Request
 PHP Version:6SVN-2009-09-11 (SVN)
 Block user comment: N

 New Comment:

I also recommend this but i have a little idea too:



1. Most of the time i use get() syntax and I have to write
new functions for that (or using __call or __set), because i protect the
properties with private or protected to protect for writing them.

2. Most of all the code is ugly or has limitations using
readonly/writeonly properties with __get(&$v) or __set($v,&$c) by
reference.

3. It is not perfectly clean to write less code with __get or
getter/setter if only want to protecting them... And less code matters!



I would like to see a new, or 2 new keywords, e.g. "readonly" and
"writonly", because the code will look smoother and i dont have to make
the use of magic methods... Or some own designed errors for that...



Now an simple example:

==







( what about is_readable() or is_writable() for that? )

I dont think that these functions will be used, so only Reflection
should be extended...



and now, instead of the current syntax:

==



$v;

  }

  function __set($v, $c)

  {

if ($v == 'foo') {

  trigger_error('$foo is not writable from this
context',E_USER_ERROR);

}

$this->$v = $c;

return true;

  }

}

?>



get/set syntax will be nice but also nasty if only read/writablity is
desired...



this can be confusing as this:

==

foo;

}

function __set() {

  trigger_error('$foo is not writable from this
context',E_USER_ERROR);

}

  } = 1;

  static protected $bar {

function __get() {

  trigger_error('$bar is not readable from this
context',E_USER_ERROR);

}

function __set() {

  $this->bar = 1;

  return true;

}

  } = 2;

}

?>



think about it... many developers will waive the old way or functions
like getVarname and setVarname... and for all other, getter/setter will
be nice as described in the rfc...


Previous Comments:

[2009-09-13 19:56:24] president at basnetworks dot net

For reference, the RFC for this feature request now exists at this URL:



http://wiki.php.net/rfc/propertygetsetsyntax


[2009-09-13 04:24:08] president at basnetworks dot net

Hi Kalle,



Thanks for the information.  I will follow your instructions and start
working on the RFC over the next week(s).  Also, thanks for the link
about the Developer Summit, but it does not show the outcome of the
discussion, am I able to find that anywhere?


[2009-09-12 12:22:19] ka...@php.net

Hey



The best way to request this feature is to write an RFC in our wiki at:

http://wiki.php.net/rfc/



Request an account at:

http://wiki.php.net/start?do=register



And then send an email to the webmaster list
(php-webmas...@lists.php.net) requesting write access to the rfc
namespace and repost this feature request as an RFC. When you are done,
start a new thread on internals (intern...@lists.php.net) explaining
your RFC.



As for reference, this idea was discussed at the last PDM in May, see:

http://wiki.php.net/summits/pdmnotesmay09#php_6 point #16


[2009-09-11 01:02:26] president at basnetworks dot net

Description:

I would like to request a C# style get/set syntax (called a property in
C#) for PHP.  Basically, it looks and acts like a class member/variable
from outside the class, but it is actually a set of two methods.  It can
be used to provide only read or write access to a class member, do pre
or post processing on a member, or be completely dynamic like a set of
class methods.



A property contains two methods between braces, named get and set.  get
must always have a return statement, while set has a magic variable
"value" or "$value" which is the variable that was passed to the
property.  Either method can be omitted to make the property read-only
or write-only.



The same effect can be achieved by creating a GetVar() and SetVar()
method to create a sudo-property "var", although it is by far much
clumsier and less intuitive.



I also realize the same effect received outside the class can be
achieved using the __get() and __set() methods, but these methods are
only really useful in a small instance of situations, like giving access
to an internal array as though each index is a property.  These magic
methods are not at all useful for using on a

#49526 [Com]: C# style property get/set syntax

2009-09-13 Thread president at basnetworks dot net
 ID:  49526
 Comment by:  president at basnetworks dot net
 Reported By: president at basnetworks dot net
 Status:  Open
 Bug Type:Feature/Change Request
 PHP Version: 6SVN-2009-09-11 (SVN)
 New Comment:

For reference, the RFC for this feature request now exists at this
URL:

http://wiki.php.net/rfc/propertygetsetsyntax


Previous Comments:


[2009-09-13 04:24:08] president at basnetworks dot net

Hi Kalle,

Thanks for the information.  I will follow your instructions and start
working on the RFC over the next week(s).  Also, thanks for the link
about the Developer Summit, but it does not show the outcome of the
discussion, am I able to find that anywhere?



[2009-09-12 12:22:19] ka...@php.net

Hey

The best way to request this feature is to write an RFC in our wiki
at:
http://wiki.php.net/rfc/

Request an account at:
http://wiki.php.net/start?do=register

And then send an email to the webmaster list
(php-webmas...@lists.php.net) requesting write access to the rfc
namespace and repost this feature request as an RFC. When you are done,
start a new thread on internals (intern...@lists.php.net) explaining
your RFC.

As for reference, this idea was discussed at the last PDM in May, see:
http://wiki.php.net/summits/pdmnotesmay09#php_6 point #16



[2009-09-11 01:02:26] president at basnetworks dot net

Description:

I would like to request a C# style get/set syntax (called a property in
C#) for PHP.  Basically, it looks and acts like a class member/variable
from outside the class, but it is actually a set of two methods.  It can
be used to provide only read or write access to a class member, do pre
or post processing on a member, or be completely dynamic like a set of
class methods.

A property contains two methods between braces, named get and set.  get
must always have a return statement, while set has a magic variable
"value" or "$value" which is the variable that was passed to the
property.  Either method can be omitted to make the property read-only
or write-only.

The same effect can be achieved by creating a GetVar() and SetVar()
method to create a sudo-property "var", although it is by far much
clumsier and less intuitive.

I also realize the same effect received outside the class can be
achieved using the __get() and __set() methods, but these methods are
only really useful in a small instance of situations, like giving access
to an internal array as though each index is a property.  These magic
methods are not at all useful for using on an individual property basis,
and it gets worse when inheritance is introduced.

The C# syntax is as follows:

class TimePeriod
{
private double seconds;

public double Hours
{
get { return seconds / 3600; }
set { seconds = value * 3600; }
}
}



The PHP syntax would be similar to the following:

class TimePeriod
{
private $seconds;

public property Hours
{
get { return $this->seconds / 3600; }
set { $this->seconds = $value * 3600; }
}
}



You would use it exactly the same as a public class member:

$time = new TimePeriod();
$time->Hours = 24;
echo $time->Hours;



As opposed to the alternative:
$time = new TimePeriod();
$time->SetHours(24);
echo $time->GetHours();



Additionally, the get and set methods can have separate visibilities
like in the following example where get is public and set is protected:

public property Name
{
get { return $this->name; }
protected set { $this->name = $value; }
}



There is another ticket that is similar but not the same thing here:
http://bugs.php.net/bug.php?id=34194

It suggests separate getter/setter methods, which in my opinion are
much less intuitive.  I believe that following the C# format would help
to keep a standard format, and would be the least confusing.

The poster of that bug also fails to realize that separate visibility
levels can be achieved for properties using the C# syntax, as shown
above.



The C# documentation on properties is available here:
http://msdn.microsoft.com/en-us/library/x9fsa0sw%28VS.80%29.aspx

The C# documentation on Asymmetric Accessor Accessibility for
properties is available here:
http://msdn.microsoft.com/en-us/library/75e8y5dd%28VS.80%29.aspx






-- 
Edit this bug report at http://bugs.php.net/?id=49526&edit=1



#49526 [Com]: C# style property get/set syntax

2009-09-12 Thread president at basnetworks dot net
 ID:  49526
 Comment by:  president at basnetworks dot net
 Reported By: president at basnetworks dot net
 Status:  Open
 Bug Type:Feature/Change Request
 PHP Version: 6SVN-2009-09-11 (SVN)
 New Comment:

Hi Kalle,

Thanks for the information.  I will follow your instructions and start
working on the RFC over the next week(s).  Also, thanks for the link
about the Developer Summit, but it does not show the outcome of the
discussion, am I able to find that anywhere?


Previous Comments:


[2009-09-12 12:22:19] ka...@php.net

Hey

The best way to request this feature is to write an RFC in our wiki
at:
http://wiki.php.net/rfc/

Request an account at:
http://wiki.php.net/start?do=register

And then send an email to the webmaster list
(php-webmas...@lists.php.net) requesting write access to the rfc
namespace and repost this feature request as an RFC. When you are done,
start a new thread on internals (intern...@lists.php.net) explaining
your RFC.

As for reference, this idea was discussed at the last PDM in May, see:
http://wiki.php.net/summits/pdmnotesmay09#php_6 point #16



[2009-09-11 01:02:26] president at basnetworks dot net

Description:

I would like to request a C# style get/set syntax (called a property in
C#) for PHP.  Basically, it looks and acts like a class member/variable
from outside the class, but it is actually a set of two methods.  It can
be used to provide only read or write access to a class member, do pre
or post processing on a member, or be completely dynamic like a set of
class methods.

A property contains two methods between braces, named get and set.  get
must always have a return statement, while set has a magic variable
"value" or "$value" which is the variable that was passed to the
property.  Either method can be omitted to make the property read-only
or write-only.

The same effect can be achieved by creating a GetVar() and SetVar()
method to create a sudo-property "var", although it is by far much
clumsier and less intuitive.

I also realize the same effect received outside the class can be
achieved using the __get() and __set() methods, but these methods are
only really useful in a small instance of situations, like giving access
to an internal array as though each index is a property.  These magic
methods are not at all useful for using on an individual property basis,
and it gets worse when inheritance is introduced.

The C# syntax is as follows:

class TimePeriod
{
private double seconds;

public double Hours
{
get { return seconds / 3600; }
set { seconds = value * 3600; }
}
}



The PHP syntax would be similar to the following:

class TimePeriod
{
private $seconds;

public property Hours
{
get { return $this->seconds / 3600; }
set { $this->seconds = $value * 3600; }
}
}



You would use it exactly the same as a public class member:

$time = new TimePeriod();
$time->Hours = 24;
echo $time->Hours;



As opposed to the alternative:
$time = new TimePeriod();
$time->SetHours(24);
echo $time->GetHours();



Additionally, the get and set methods can have separate visibilities
like in the following example where get is public and set is protected:

public property Name
{
get { return $this->name; }
protected set { $this->name = $value; }
}



There is another ticket that is similar but not the same thing here:
http://bugs.php.net/bug.php?id=34194

It suggests separate getter/setter methods, which in my opinion are
much less intuitive.  I believe that following the C# format would help
to keep a standard format, and would be the least confusing.

The poster of that bug also fails to realize that separate visibility
levels can be achieved for properties using the C# syntax, as shown
above.



The C# documentation on properties is available here:
http://msdn.microsoft.com/en-us/library/x9fsa0sw%28VS.80%29.aspx

The C# documentation on Asymmetric Accessor Accessibility for
properties is available here:
http://msdn.microsoft.com/en-us/library/75e8y5dd%28VS.80%29.aspx






-- 
Edit this bug report at http://bugs.php.net/?id=49526&edit=1