> Thanks for your reply.
>
> Fundamentally, a big +1 from my little voice on having setters/getters in
> PHP.
>
>
> The issue of documentation is probably that the documentation tools
> would have to adapt. As things stand PHPDoc doesn't support
> namespaces, so setters/getters would just be added to the WIBNI list.

Here is a reply I wrote to Christan Kaps on the same subject:

>  Christan Wrote:
>
>  I like the idea of the property get/set syntax, but in my opinion it
>  doesn't figure with PHP's syntax, because it breaks the readability. The
>  problem for me is the nesting of the inner set and get. How do you
>  document these syntax.
>
>  /**
>   *
>   */
>  public $name {
>
>      /**
>       *
>       */
>      get {
>          return $this->name;
>      }
>
>      /**
>       *
>       */
>      set {
>          $this->name = htmlentities($value);
>          $this->name = strip_tags($this->name);
>      }
>  };

Typically you only document the property as a whole, and not the
individual get and set method.  Since they are a pair, there should be no
reason to document them separately.  If the get method is doing something
totally different from the set, then they should not be paired, as that is
confusing.

In C# you would typically see documentation like this:

Only a get method:
/// <summary>Gets the duration of the Timespan in seconds.</summary>
public int Seconds { get; }

Only a set method:
/// <summary>Sets the duration of the Timespan in seconds.</summary>
public int Seconds { set; }

Both a get and set method:
/// <summary>Gets/sets the duration of the Timespan in seconds.</summary>
public int Seconds { get; set; }





> With regard to the value supplied to the set method, would it make
> more sense for PHP to be ...
>
>         set($value) { $this->seconds = $value * 3600; }
>
> or
>
>         set { $this->seconds = __SETVALUE__ * 3600; }
>
> Having $value without a clear indication of where it comes from
> doesn't read quite right.
>
> $value is way to generic to be magically created. __SETVALUE__ (or
> __SOMETHINGELSE__) is clear in this regard.

That is a good point.  In C# it is simple the variable "value", which is
where I got $value from.  Rather magicy, yes.  A constant could work, and
would be more in line with PHP's magic constants.  Just a quick question
though, can a constant store all of the same data variable can?  What
about a reference?

Also, sometimes users in C# like to modify the contents of the "value"
variable before using it for something else.  If it were a constant this
would not be possible, you would have to define a new variable, then copy
the value from the constant, which seems unnecessarily cumbersome.

- Dennis


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to