Brainstorm: How to document __get() + @property $xyz + 'calc_xyz()' pattern? #3660
donquixote
started this conversation in
Ideas
Replies: 3 comments
-
A possible solution could be a @methodPrefix tag on top of the __get() method, like this: abstract class ContainerBase {
private $buffer = array();
/**
* @param string $key
*
* @return mixed
*
* @methodPrefix calc_
*/
function __get($key) {
return array_key_exists($key, $this->buffer)
? $this->buffer[$key]
: $this->buffer[$key] = $this->{'calc_' . $key}();
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Another solution could be to somehow put this into the @return tag. abstract class ContainerBase {
private $buffer = array();
/**
* @param string $key
*
* @return $this->{'calc_' . $key}()
*/
function __get($key) {
return array_key_exists($key, $this->buffer)
? $this->buffer[$key]
: $this->buffer[$key] = $this->{'calc_' . $key}();
}
} Other ideas? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Or, a smart IDE could do some code evaluation, even without any new doc tags:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
A pattern I use quite a lot in PHP is this:
I made it a habit to always add the @see tags to associate a method with a property. This is kind of ok, but requires too much work to set up, and the IDE has no way to validate it.
I wonder how this could be documented, to allow the IDE to
(Proposals in comments)
Beta Was this translation helpful? Give feedback.
All reactions