protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

PHP: The phpdoc for enum getters/setters does not point to corresponding enum class

Open bshaffer opened this issue 3 months ago • 4 comments

Feature Request for PHP:

in the phpdoc for getters and setters which correspond to an enum field, the generated class does not point to corresponding PHP enum class. The customer has no way of knowing where the enum values are held without going into the protos.

Example:

The return types and parameter types only show @return int and @param int respectively:

    /**
     * Joy likelihood.
     *
     * Generated from protobuf field <code>.google.cloud.vision.v1.Likelihood joy_likelihood = 9;</code>
     * @return int
     */
    public function getJoyLikelihood()
    {
        return $this->joy_likelihood;
    }

    /**
     * Joy likelihood.
     *
     * Generated from protobuf field <code>.google.cloud.vision.v1.Likelihood joy_likelihood = 9;</code>
     * @param int $var
     * @return $this
     */
    public function setJoyLikelihood($var)
    {
        GPBUtil::checkEnum($var, \Google\Cloud\Vision\V1\Likelihood::class);
        $this->joy_likelihood = $var;

        return $this;
    }

What we'd like to see instead

We can link the return and parameter types to the corresponding enum class:

    /**
     * Joy likelihood.
     *
     * Generated from protobuf field <code>.google.cloud.vision.v1.Likelihood joy_likelihood = 9;</code>
-    * @return int
+    * @return int one of the values in {@see \Google\Cloud\Vision\V1\Likelihood}.
     */
    public function getJoyLikelihood()
    {
        return $this->joy_likelihood;
    }

    /**
     * Joy likelihood.
     *
     * Generated from protobuf field <code>.google.cloud.vision.v1.Likelihood joy_likelihood = 9;</code>
-    * @param int $var
+    * @param int $var one of the values in {@see \Google\Cloud\Vision\V1\Likelihood}.
     * @return $this
     */
    public function setJoyLikelihood($var)
    {
        GPBUtil::checkEnum($var, \Google\Cloud\Vision\V1\Likelihood::class);
        $this->joy_likelihood = $var;

        return $this;
    }

This would also be implicitly fixed by implementing PHP native enums! See https://github.com/protocolbuffers/protobuf/issues/15567

bshaffer avatar Sep 04 '25 22:09 bshaffer

@piotrgradzinski to potentially work on this

bshaffer avatar Sep 04 '25 22:09 bshaffer

Assigning this to @bshaffer to assign when ready to work on.

jguamie avatar Sep 09 '25 17:09 jguamie

unassigning this because I do not have this prioritized yet, but it's on our backlog as ready to work on

bshaffer avatar Nov 13 '25 22:11 bshaffer

@bshaffer can you please reassign this issue to me and close it? I don't have permission to do it. Thanks!

piotrgradzinski avatar Nov 30 '25 10:11 piotrgradzinski